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();

                    }
                }

Recommended Answers

All 5 Replies

What line are you getting that exception on?

Hi,
When loop is entering in the next table.

Suppose,
10 rows in datagridview. First five rows are in [01] table and next five rows in [02] table each table contain 2000 records. when loop entering into 6 th row it will throw an exception of time expired.


Can u help me.............

Thanks in advance

try to increase the command.timeout

Thanks for Reply it works...Pgmer

Cheers...Please mark the thread as solved if it is solved..:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.