Hi,
I am getting an error while fetching the records from sql server to datagridview. Ex. I have 10 rows in datagridview first five are with one table and next five for another table. When loop goes for next table it throws an error like "timeout expired. the timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated."
How can i solve this......... Thanks in advance.
for (int h = 0; h <= dtgqueformat.RowCount - 2; h++)
{
string avl_subject = dtgqueformat[8, h].Value.ToString();
string avl_chapter = dtgqueformat[9, h].Value.ToString();
if (avl_subject != "")
{
string TableName = "";
if (avl_subject == "01 Biology")
{
TableName = "[01]";
}
else if (avl_subject == "02 Physics")
{
TableName = "[02]";
}
else if (avl_subject == "03 Chemistry")
{
TableName = "[03]";
}
else if (avl_subject == "04 Mathematics")
{
TableName = "[04]";
}
string str_select = "select * from " + TableName + " where RepeatQno=0";
cmd = new SqlCommand(str_select, connect.getConnection());
cmd.Connection.Open();
dr=cmd.ExecuteReader ();
if (dr.Read())
{
string que_no = "";
dtgqueformat [4,h].Value =dr["que"].ToString ();
dtgqueformat[13, h].Value = dr["Srno"].ToString();
que_no = dr["Srno"].ToString();
string str_update = "update " + TableName + " set RepeatQno=1 where Srno = " + que_no;
cmd = new SqlCommand(str_update, connect.getConnection());
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
}
cmd.Connection.Close();
}
}