OleDb UPDATE查询

时间:2017-05-28 17:40:41

标签: c# database ms-access oledbcommand

我是C#中使用Access数据库的新手,想知道是否可以替换此代码

string sql = "UPDATE Volunteer SET
VolunteerName =  @VolunteerName, 
NickName = @NickName,
ContactNo = @ContactNo
WHERE VolunteerID = @VolunteerID ";

dbCmd = new OleDbCommand(sql, dbConn);
dbCmd.Parameters.AddWithValue("@VolunteerName", txtLastName.Text);
dbCmd.Parameters.AddWithValue("@NickName", txtFirstName.Text);
dbCmd.Parameters.AddWithValue("@ContactNo", txtContact.Text);
dbCmd.Parameters.AddWithValue("@VolunteerID", txtVolunteerID.Text);

与此类似的东西

string sql = "UPDATE Volunteer SET
VolunteerName = "+ txtLastName.Text +", 
NickName = "+ txtFirstName.Text +",
ContactNo = "+ txtContact.Text +"
WHERE VolunteerID = "+ txtVolunteerID.Text ";

dbCmd = new OleDbCommand(sql, dbConn);

0 个答案:

没有答案