Hello,
I want to save multiple record in database from DataGridView. I have some code but their is an error i.e
Column named id cannot be found.
Paramater name:columnName
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "path of connection";
cn.Open();
string q = "select * from abc";
SqlDataAdapter da = new SqlDataAdapter(q, cn);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
DataTable dt = new DataTable();
da.Fill(dt);
foreach (dataGridView1 row in dataGridView1.Rows)
{
SqlDataAdapter da1 = new SqlDataAdapter();
da1.InsertCommand = new SqlCommand("insert into abc(id,name,adderss)values(@id,@name,@address)", cn);
[B] da1.InsertCommand.Parameters.Add("@id", row.cells["id"].Value);[/B] da1.InsertCommand.Parameters.Add("@name", row.cells["name"].Value);
da1.InsertCommand.Parameters.Add("@address", row.cells["address"].Value);
DataSet ds = new DataSet();
da1.Fill(ds);
dataGridView1.DataSource = ds;
}
da.Update(dt);
Please give me solution.