更新未更新

时间:2013-10-29 17:30:39

标签: c# sql sql-update

我正在尝试通过我的代码更新SQL Server中的表。我已经完成了代码,所有准确和正确的值似乎都在通过。有人可以看看这个并告诉我,我是否在某处犯了错误?提前谢谢。

public static string Update()
{
   string connectionString = null;
   SqlConnection connection;
   SqlDataAdapter adapter = new SqlDataAdapter();
   string sql = null;
   connectionString = Connection.MyConnectionString.ConnectionStrings[0];
   connection = new SqlConnection(connectionString);
   sql = "UPDATE tbl_Onsite SET Onsite = 'Yes' WHERE BoxNum = GlobalVariable.Variables.BoxNumber";
   try{
       connection.Open();
       adapter.UpdateCommand = connection.CreateCommand();
       adapter.UpdateCommand.CommandText = sql;
       adapter.UpdateCommand.ExecuteNonQuery();
  } 
  catch(Exception ex){
       MessageBox.Show(ex.ToString());
  }
  return null;
  }

1 个答案:

答案 0 :(得分:3)

试试这个

sql = "UPDATE tbl_Onsite SET Onsite = 'Yes' WHERE BoxNum = " + GlobalVariable.Variables.BoxNumber;