如何使用oledb参数更新表?
我有一个有三个字段的表,即LM_code,M_Name,Desc。LC_code是一个自动生成的字符串Id,保持这个我正在更新M_Name和Desc。我使用了普通的更新命令,该值在运行时传递,但字段没有得到更新。我希望使用oledb参数可以更新字段。
这是我的代码。
public void Modify(){
String query = "Update Master_Accounts set (M_Name='" + M_Name + "',Desc='" + Desc + "') where LM_code='" + LM_code + "'";
DataManager.RunExecuteNonQuery(ConnectionString.Constr, query);}在DataManager类中,我正在执行查询字符串。
public static void RunExecuteNonQuery(string Constr, string query){
OleDbConnection myConnection = new OleDbConnection(Constr);
try
{
myConnection.Open();
OleDbCommand myCommand = new OleDbCommand(query, myConnection);
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
string Message = ex.Message;
throw ex;
}
finally
{
if (myConnection.State == ConnectionState.Open)
myConnection.Close();
}}private void toolstModify_Click_1(object sender, EventArgs e){
txtamcode.Enabled = true;
jewellery.LM_code = txtamcode.Text;
jewellery.M_Name = txtaccname.Text;
jewellery.Desc = txtdesc.Text;
jewellery.Modify();
MessageBox.Show("Data Updated Succesfully");}慕仙森
相关分类