This code insert all the the rows of datagridview as different rows in database with same vendor name. Here is my code. database table where gridview data insert into different rows.
43 7869 Bouzia Pharamectuial(pvt) Ld 0000-00-00 00:00:00 0 0 1741 45 abc pending 36005
44 7869 Bouzia Pharamectuial(pvt) Ld 0000-00-00 00:00:00 0 0 1741 35 As pharma pending 36005
string StrQuery;
connString = "[enter image description here][1]";
try
{
conn = new MySqlConnection();
conn.ConnectionString = connString;
conn.Open();
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Connection = conn;
for (int i = 0; i < invoice_insertion_grid_view.Rows.Count -1; i++)
{
StrQuery = @"INSERT INTO purchasing Values('','" + bill_purchasing_invoice_textbox.Text + "','" + bill_purchasing_vendor_combobox.SelectedItem.ToString() + "','" + bill_purchasing_date_textbox.Value.Date + "','','','" + bill_purchasing_total_balance_textbox.Text + "','" + invoice_insertion_grid_view.Rows[i].Cells["quantity"].Value + "','" + invoice_insertion_grid_view.Rows[i].Cells["medicine_name"].Value + "','pending','" + purchasing_invoice_payable_box.Text + "')";
cmd.CommandText = StrQuery;
cmd.ExecuteNonQuery();
}
MessageBox.Show("Data is inserted successfully");
cmd.Dispose();
conn.Close();
}
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show(ex.Message);
}