I have a datagridview that it's columnNames are equal to my columns in access database
Now I want this:
whene user click on savebtn all of datagridview columns values automatically updated to my database,
I've tried this code but it get me syntax error :
{"Syntax error (missing operator) in query expression '@1Where FeedID=@feedID'."}
where is the problem?
public void UpdatetFeeds(DataGridView dgv)
{
string StrCon = System.Configuration.ConfigurationManager.ConnectionStrings
["FeedLibraryConnectionString"].ConnectionString;
int FeedID = Convert.ToInt32(dgv.CurrentRow.Cells[0].Value);
using (OleDbConnection Connection = new OleDbConnection(StrCon))
{
Connection.Open();
using (OleDbCommand Cmd = new OleDbCommand())
{
Cmd.Connection = Connection;
foreach (DataGridViewColumn column in dgv.Columns)
{
string columnName = dgv.Columns[column.Index].Name;
object columnValue = dgv.CurrentRow.Cells[column.Index].Value;
Cmd.CommandText = @"Update tFeeds Set " + columnName + " =@"
+ columnValue + "Where FeedID=@feedID";
Cmd.Parameters.Add("@feedID", OleDbType.Integer).Value = FeedID;
Cmd.ExecuteNonQuery();
}
}
}
}