Results 1 to 4 of 4

Thread: Can we open Two SQL Command Object at a time

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    141

    Angry Can we open Two SQL Command Object at a time

    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
    Last edited by Waseemalisyed; May 21st, 2005 at 01:03 AM. Reason: enhance

  2. #2
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Can we open Two SQL Command Object at a time

    Read the MachineNo's Into an array... Close the DataReader Then Loop Thru the Machine Numbers Executing your SP.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    141

    Angry Re: Can we open Two SQL Command Object at a time

    can we count record in dataReader
    with out loop

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464

    Re: Can we open Two SQL Command Object at a time

    Try creating two different sql connections if you absolutely must have two readers open at the same time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width