Error in executing SP using ExecuteReader.

Posted by Incubator under ASP.NET on 7/30/2012 | Points: 10 | Views : 1678 | Status : [Member] | Replies : 1
Hi
I have a windows application in .Net Framework 2.0 working with MySQL version 5.0. I am executing a SP from my application as shown below. It showing an error "No current query in data reader".


public static DataTable loadUsers()
{
DataTable dtUsers = new DataTable();
DataColumn dcUsers;
DataRow drUsers;
//Executing the SP with helper class and fetching the data to the data set and return the data set.
try
{
//Create a new data set object to store the values
MySqlDataReader dr = MySqlHelper.ExecuteReader(Base.strConnString, "call get_de_users()");

DataTable schemaTable = dr.GetSchemaTable();

for (int i = 0; i < schemaTable.Rows.Count; i++)
{
dcUsers = new DataColumn();
if (!dtUsers.Columns.Contains(schemaTable.Rows[i]["ColumnName"].ToString()))
{
dcUsers.ColumnName = schemaTable.Rows[i]["ColumnName"].ToString();
dcUsers.Unique = Convert.ToBoolean(schemaTable.Rows[i]["IsUnique"]);
dcUsers.AllowDBNull = Convert.ToBoolean(schemaTable.Rows[i]["AllowDBNull"]);
dcUsers.ReadOnly = Convert.ToBoolean(schemaTable.Rows[i]["IsReadOnly"]);
dtUsers.Columns.Add(dcUsers);
}
}

drUsers = dtUsers.NewRow();
drUsers["USER_NAME"] = "";
drUsers["USER_ID"] = "0";
drUsers["PASSWORD"] = "";
drUsers["USER_ROLE"] = "0";
drUsers["WORK_SHIFT"] = "";
drUsers["TEAMLEADER_ID"] = "0";

dtUsers.Rows.InsertAt(drUsers, 0);
while (dr.Read())
{

drUsers = dtUsers.NewRow();
for (int i = 0; i < dr.FieldCount; i++)
{
drUsers[i] = dr.GetValue(i);
}
dtUsers.Rows.Add(drUsers);
}
dr.Close();
}
catch (Exception e)
{
//Log the exception in the log and then return the empty data set.
throw e;
}
finally
{
Base.DBClose();
}



Can any one help me....

Thanks
Incubator




Responses

Posted by: Rajkatie on: 8/2/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Refer following link
http://etutorials.org/Programming/ado+net/Part+I+ADO.NET+Tutorial/Chapter+5.+DataReaders/5.2+Performing+a+Query+with+a+DataReader/

Rajesh Patel
.Net Trainer(MSCD | MCT | MS)
Brainbench (Asp.Net 4.5 and C# 5.0)

Incubator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response