0

我正在尝试通过我的代码更新 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;
  }
4

1 回答 1

3

试试这个

sql = "UPDATE tbl_Onsite SET Onsite = 'Yes' WHERE BoxNum = " + GlobalVariable.Variables.BoxNumber;
于 2013-10-29T17:37:57.073 回答