Meena S

Meena S

  • NA
  • 48
  • 4k

how to fill database and textbox value same row datagrid

May 10 2019 1:01 AM
I want to fill first 3 columns based on combobox select other 2 columns from textbox values
 
I done code in combobox seletectedindexchanged event. but it fills data to next row
  1. private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)  
  2. {  
  3. OleDbConnection con = new OleDbConnection(@"Provider=SQLOLEDB;Data Source=DESKTOP\SQLEXPRESS;User ID=sa; Password = REGENT; Initial Catalog=Meena; Integrated secutity=SSPI");  
  4. DataSet ds = new DataSet();  
  5. DataTable dt = new DataTable();  
  6. con.Open();  
  7. OleDbCommand cmd = new OleDbCommand(("Select t1.itemcode, t2.Description, t1.UOM from Item t1 INNER JOIN ItemGroup t2 ON t1.Itemcode = '" + comboBox3.Text + "'"), con);  
  8. OleDbDataAdapter da = new OleDbDataAdapter();  
  9. da.SelectCommand = cmd;  
  10. DataRow dr = dt.NewRow();  
  11. da.Fill(dt);  
  12. dt.Columns.Add("Quantity");  
  13. dt.Columns.Add("Rate");  
  14. dt.Columns.Add("Amount");  
  15. dr[3] = textBox3.Text;  
  16. dr[4] = textBox5.Text;  
  17. dt.Rows.Add(dr);  
  18. if (dt.Rows.Count > 0)  
  19. {  
  20. dataGridView1.DataSource = dt;  
  21. }  
  22. }  

Answers (1)