I have been tring to figure out how to know when a stored procedure (such as .ExecuteNonQuery()) has completed.
I have a loop that is for a text reader that is looking up ID's of records in the SqlServer table that need to be updated. However the loop is faster than the server and I am trying to figure out how to make the loop wait
Example:
using (tr = File.OpenText(myFilePath)
{
SqlCommand UpdateCmd = new SqlCommand("MyStoredProcedure", conn);
UpdateCmd.CommandType = CommandType.StoredProcedure;
while((templine = tr.ReadLine()) != null)
{
conn.Open();
UpdateCmd.Parameters.AddWithValue("@IDNumber", templine);
UpdateCmd.ExecuteNonQuery();
//this is the point at which I need to Wait for the Nonquery to finish.. How?
conn.Close();
}
}
I can get errors on similar issues like connection still open or you already have an open reader. etc.
Is there a quick and dirty way to make it wait for procedure to wait?
Any help will be appreciated.
Thanks
Frank