Update to SQL Server is NOT Working

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
 
M

Marina

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.
 
S

someone

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top