user2932408
user2932408

Reputation: 65

Update Not Updating

I am attempting to update a table in SQL Server via my code. I have stepped through the code, and all accurate and correct values appear to be passing. Can someone look this over and tell me if I made a mistake somewhere? Thanks in advance.

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;
  }

Upvotes: 0

Views: 80

Answers (1)

Esteban Elverdin
Esteban Elverdin

Reputation: 3582

Try this

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

Upvotes: 3

Related Questions