PDA

Click to See Complete Forum and Search --> : Can we open Two SQL Command Object at a time


Waseemalisyed
May 21st, 2005, 12:16 AM
Can we open Two SQL Command or SQL DataReader Object at a time

SqlCommand cmSQL = new SqlCommand("select * from PD_ComMachines",G1.cn);
SQLDR = cmSQL.ExecuteReader();

while (SQLDR.Read())
{
FillGrid(int.Parse(SQLDR["MachineNo"].ToString()));
}

internal void FillGrid(int MachineNO)
{
try
{
SqlCommand cmdFill = new SqlCommand ("ComberMachine",G1.cn);
cmdFill.CommandType=CommandType.StoredProcedure;
cmdFill.Parameters.Add("@machNo", SqlDbType.Int);
cmdFill.Parameters["@machNo"].Value = MachineNO;
cmdFill.Parameters["@machNo"].Direction = ParameterDirection.Input;

cmdFill.Parameters.Add("@Name", SqlDbType.VarChar,20);
cmdFill.Parameters["@CODateo"].Direction = ParameterDirection.Output;

cmdFill.ExecuteNonQuery();
System Generate Error :There is already an Open DataReader Assciateed with this connection which must be closed


// Retrive result from stored procedure
Name = (string)cmdFill.Parameters["@Name"].ToString();
TextBox1.Text = Name

<ABX
May 21st, 2005, 02:36 AM
Read the MachineNo's Into an array... Close the DataReader Then Loop Thru the Machine Numbers Executing your SP.

Waseemalisyed
May 21st, 2005, 03:10 AM
can we count record in dataReader
with out loop

hellswraith
May 21st, 2005, 12:42 PM
Try creating two different sql connections if you absolutely must have two readers open at the same time.