我有一个datagridview
,它的columnNames等于access database
现在我想要这个:
当用户点击savebtn
所有datagridview
列值自动更新到我的数据库时,
我已经尝试过这段代码,但它让我syntax error
:
{"查询表达式中的语法错误(缺少运算符)' @ 1Where FeedID = @ feedID'。"}
问题出在哪里?
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();
}
}
}
}
答案 0 :(得分:1)
似乎至少你失去了空间
xxd msb.tif| more
0000000: 4d4d 002a 0006 0008 ffff 0000 0000 ffff MM.*............
此外,您在此处拥有哪种数据:" Where FeedID=@feedID";
。看来你需要braskets:" =@" + columnValue + "