Update to SQL Server is NOT Working

  • Thread starter Thread starter someone
  • Start date Start date
S

someone

I am using the following code in response to a button press.
SqlConnection sqlConn;
SqlCommand sqlCmd;

sqlUpdate = "update ACCGreatest set Votes = (select Votes
+ 1 from ACCGreatest where PlayerID = " +
Convert.ToInt32(ddlGreatest.SelectedItem.Value.ToString()) + ") where
PlayerID = " + Convert.ToInt32(ddlGreatest.SelectedItem.Value);
sqlConn = new
SqlConnection("server=(local);uid=accfb;password=accrules;database=ACCFB");
sqlCmd = new SqlCommand(sqlUpdate, sqlConn);
sqlConn.Open();
try
{
sqlCmd.ExecuteNonQuery();
}
catch(SqlException ae)
{
Response.Write("SQL Exception: " + ae.ToString());
}
sqlConn.Close();

Unfortunately, it is not working. Can anyone see why this would be
happening? I can take the update string and use it in the SQL Analyzer
and it works fine. So what gives?

TIA,
Mike
 
What is the exception you are getting? What is the line number that causes
the issue?

Also, why are you converting a string to an intenger? You are concatenating
strings - so leave it as a string. This may be the cause of your problem.
 
The data type in the database is int so I assumed that I needed to
convert it to the appropriate data type.
The weird thing is that it is not throwing an error but still not
performing the update. Does my approach seem reasonable to you?
- Create a connection
- Create a sql command based on the connection
- Open the connection
- Execute a non query
- Close the connection
All seems pretty straight forward to me. I have a datagrid that has
been easier to work with than this!! ARGH

Mike
 
Back
Top