ExecuteReader Error Problem

Posted by Rrana under C# on 9/1/2011 | Points: 10 | Views : 1885 | Status : [Member] | Replies : 1
Hi,

When i execute my code, it shows error like this

ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.


My Code id:====

public DataTable ExecuteDataTable(string strProcName, IDbDataParameter[] param)
{
DataTable dtReturn = null;

try
{
dtReturn = new DataTable();
dbAdp = new SqlDataAdapter();
dbCmd = new SqlCommand();
dbCmd.Connection = dbCon;
dbCmd.CommandType = CommandType.StoredProcedure;
dbCmd.CommandText = strProcName;
if (param != null && param.Length > 0)
{
dbCmd.Parameters.AddRange(param);
}
dbAdp.SelectCommand = dbCmd;
dbAdp.Fill(dtReturn);
return dtReturn;
}
catch (Exception ex)
{
throw ex;
}
finally
{
dbCon.Close();
}
}

Thanks in Advance

Sucharitha Goud
Bank Of America..



Responses

Posted by: SheoNarayan on: 9/1/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Hi Rrana,

Read these posts for your solution

http://social.msdn.microsoft.com/forums/en-US/vbgeneral/thread/e17ac906-7eae-41e3-b214-56fd7bcaab76
http://yoy.be/item.asp?i1248

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

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

Login to post response