I have two tables in a SQL Server database, product and innvoice.
I am fetching selected data from table product and showing them in datagridview.
Now I want to store data from datagridview to table innvoice. This all operation takes on one button click.
Here is my code:
private void button5_Click_2(object sender, EventArgs e) //add produt
{
SqlConnection con = new SqlConnection(@"Persist Security Info=False;User ID=usait;password=123;Initial Catalog=givenget;Data Source=RXN-PC\ROSHAAN");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECT product.p_name,product.p_category, product.sale_price FROM product where p_code='" + textBox16.Text + "'", con);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView3.DataSource = dt;
// here I want to insert values from datagridview3 to table innvoice.
}
Invoice- one "n" only. And you should stop concatenating together your SQL statements - that's just inviting hacker to exploit your SQL injection weakness! Use parametrized queries - always.