Meena S

Meena S

  • NA
  • 48
  • 4.4k

display data to datagridview from database

Jun 6 2019 9:36 AM
When am trying to display data to datagridview from database, only first row inserted properly
 
please find the below code. please correct the below code
  1. public void filldata(String bno)  
  2. {  
  3. textBox1.Text = bno;  
  4. OleDbConnection con = new OleDbConnection(@"Provider=SQLOLEDB;Data Source=DESKTOP\SQLEXPRESS;User ID=sa; Password = REGENT; Initial Catalog=Meena; Integrated secutity=SSPI");  
  5. con.Open();  
  6. OleDbCommand cmd = new OleDbCommand(("Select * from data1 where Sno = '" +bno +"'"), con);  
  7. OleDbDataAdapter da = new OleDbDataAdapter();  
  8. da.SelectCommand = cmd;  
  9. DataTable dt = new DataTable();  
  10. da.Fill(dt);  
  11. dataGridView1.AutoGenerateColumns = false;  
  12. dataGridView1.DataSource = dt;  
  13. dataGridView1.Columns[1].DataPropertyName = "Itemcode";  
  14. dataGridView1.Columns[2].DataPropertyName = "Description";  
  15. dataGridView1.Columns[3].DataPropertyName = "Uom";  
  16. dataGridView1.Columns[4].DataPropertyName = "Qunatity";  
  17. dataGridView1.Columns[5].DataPropertyName = "Rate";  
  18. dataGridView1.Columns[6].DataPropertyName = "Amount";  
  19. con.Close();  


 
In the above picture, three fields not filled in datagrid. How to resolve this issue.

Answers (9)