By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,347 Members | 2,120 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,347 IT Pros & Developers. It's quick & easy.

datagridview control

P: 13
hello..!!! can any bodt tell me how to bind datagridview in winform this is my code but gridview is not displaying the data, i dont know where i did the mistake

Expand|Select|Wrap|Line Numbers
  1. SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\simullat ion\\simullation\\simullation.mdf;Integrated Security=True;User Instance=True");
  2. con.Open();
  3. DataSet ds = new DataSet();
  4. //DataTable table = new DataTable("Unit_Master");
  5. SqlDataAdapter da = new SqlDataAdapter("insert into Unit_Master(UnitValues) values('" + txtUnitValues.Text.Trim() + "')", con);
  6. da.Fill(ds, "Unit_Master");
  7. dataGridView1.DataSource = ds.Tables["Unit_Master"].DefaultView;
  8. dataGridView1.DataMember = "Unit_Master";
  9. dataGridView1.AutoResizeRows(DataGridViewAutoSizeR owsMode.AllCells);
  10. dataGridView1.Refresh();
  11. da.Update(ds);
  12. //dataGridView1.DataSource = table;
Dec 30 '08 #1
Share this Question
Share on Google+
3 Replies


Frinavale
Expert Mod 5K+
P: 9,731
First check that your connection string is correct and then please step through your application using the debugger.

Check to see if your DataSet is getting filled and un-comment the line where you are setting the DataGridView's DataSource. If you don't set the DataGridView's DataSource then it will not display.

Why are you updating the DataSet?
Dec 30 '08 #2

Expert 100+
P: 190
The DataAdapter command is an Insert statement, not a Select statement, so there are no rows being placed into the the DataTable.
Jan 10 '09 #3

P: 1
change your query from insert to select.
like
Select * from Unit_Master
Jan 11 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.