Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
try
           {
               sqlConnection.Open();
               sqlCommand = new SqlCommand(strQuery, sqlConnection);
               sqlReader = sqlCommand.ExecuteReader();

               while (sqlReader.Read())
               {

                   object[] row = { sqlReader[0]};
                   dataGridView1.Rows.Add(row);
               }

           }
           catch (Exception exc)
           {
               MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               return;
           }
           finally
           {
               Cursor.Current = Cursors.Default;
               sqlConnection.Close();
               if (sqlReader != null)
               {
                   sqlReader.Dispose();
                   sqlReader = null;
               }
               if (sqlCommand != null)
               {
                   sqlCommand.Dispose();
                   sqlCommand = null;
               }
           }
       }

i see system hang on while executing this line
object[] row = { sqlReader[0]};

and nothing is displayed in gridview, but when i add messagebox.show("code check"); than record is displayed with every time it picks data from database

any suggestion
Posted
Updated 27-Nov-11 20:01pm
v2
Comments
thatraja 28-Nov-11 2:01am    
Why did you tag your question as VB while your code in C#? :Doh:

1 solution

http://www.dotnetperls.com/datagridview-tutorial[^]

Check this link and insert like that way....:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900