473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Update to SQL Server is NOT Working

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.ToS tring()) + ") where
PlayerID = " + Convert.ToInt32(ddlGreatest.SelectedItem.Value);
sqlConn = new
SqlConnection("server=(local);uid=accfb;password=a ccrules;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
Nov 17 '05 #1
2 2129
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.

"someone" <so*****@somewhere.com> wrote in message
news:cc********************************@4ax.com...
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.ToS tring()) + ") where
PlayerID = " + Convert.ToInt32(ddlGreatest.SelectedItem.Value);
sqlConn = new
SqlConnection("server=(local);uid=accfb;password=a ccrules;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

Nov 17 '05 #2
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

On Mon, 7 Jul 2003 16:38:57 -0400, "Marina"
<zl*******@nospam.hotmail.com> wrote:
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.

"someone" <so*****@somewhere.com> wrote in message
news:cc********************************@4ax.com.. .
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.ToS tring()) + ") 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


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
5
by: HydroSan | last post by:
Having a bit of a problem getting UPDATE working. The project in question is a simple MySQL VB.NET frontend, allowing Insertion, Selection, and others. Well, I've gotten Drop and Insert working,...
29
by: Geoff Jones | last post by:
Hi All I hope you'll forgive me for posting this here (I've also posted to ado site but with no response so far) as I'm urgently after a solution. Can anybody help me? I'm updating a table on...
8
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
0
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
0
by: sdash | last post by:
I'm working on a simple formview screen that should update a SQL Server 2000 record. I'm sure there must be something simple wrong, but when I press update, the screen refreshes and the changes...
6
by: Rudy | last post by:
Hello all! I'm working in vb/ado.net I want to to have a message box pop up based on a result of a update on a SQL table. How do I do that so it automaticly pops up after the update is...
2
by: travhale | last post by:
in a new project using .net 2005, c#. getting err message "Update requires a valid UpdateCommand when passed DataRow collection with modified rows." source RDBMS is oracle 8i. I add a new...
3
by: J055 | last post by:
Hi I have a PlaceHolder control inside a FormView EditItemTemplate: <asp:PlaceHolder ID="phResponseText" runat="server"> <tr> <td> <asp:Label ID="lblResponseText"...
3
by: Brad Baker | last post by:
I have a formview with a datasource that contains a select and update command. The select statement works fine but the update command doesn't seem to be working. After some troubleshooting I have...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.