hi,
how to assigning variables from gridview to database table in C#?
thanx
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
roy himanshuPosted Sep 15, 2009, 12:10 AM
Roei BarPosted Sep 14, 2009, 2:21 PM
do you want to retrieve data by filter ?
can you provide some more specific information for me to help you out
Master BillaPosted Sep 14, 2009, 11:44 AM
You can write code like this way.
private void SaveDataToDatabase()
{
using (SqlConnection con = new SqlConnection("connection"))
{
using (SqlCommand cmd = con.CreateCommand())
{
foreach (DataGridViewRow item in dataGridView1.Rows)
{
cmd.CommandText = "insert tableName(columns name here) values(" + item.Cells[0] + ")"; cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
}
}
Note:You can read cell data by index and set to query value.
thank you