473,395 Members | 1,972 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,395 software developers and data experts.

UPDATE query not working

I am trying to create an update query but it is failing to make any changes.
Below is the code I have...
Expand|Select|Wrap|Line Numbers
  1.     Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
  2.         Dim strSqlEditRecord As String
  3.         Dim myCmd As OleDb.OleDbCommand
  4.         myCmd = Nothing
  5.         strSqlEditRecord = "UPDATE tblMain SET Per_Hour_Quota= '" & txtQuota.Text & "' WHERE EnteredRecord= '" & lblRecordNumber.Text & "';"
  6.         myCmd = New OleDb.OleDbCommand(strSqlEditRecord, gMDB)
  7.         myCmd.Parameters.AddWithValue("@Per_Hour_Quota", txtQuota.Text)
  8.         myCmd.CommandType = CommandType.Text
  9.         myCmd.CommandTimeout = 60
  10.         myCmd.ExecuteNonQuery()
  11.         MsgBox("This record has been updated in the database.", MsgBoxStyle.Information, "Saved Record")
  12.         Clear()
  13.     End Sub
I have a form with a button to query the db and return records based on the criteria selected. The idea here is to allow the user to then make changes to that record and save back to the db. Can anyone tell me where the error is? Thanks!!
Feb 8 '08 #1
10 1072
nateraaaa
663 Expert 512MB
There is an easy way to troubleshoot database errors. Surround your code with a try catch block. If the code in the try does not successfully execute the code will fall into the catch block giving you details of the problem.

Nathan
Feb 8 '08 #2
DrBunchman
979 Expert 512MB
Have you tried running your update query in Management Studio first to see whether it works?

Is your code erroring and causing an exception?

Dr B
Feb 8 '08 #3
There is an easy way to troubleshoot database errors. Surround your code with a try catch block. If the code in the try does not successfully execute the code will fall into the catch block giving you details of the problem.

Nathan
I tried...
Expand|Select|Wrap|Line Numbers
  1.         Try
  2.             myCmd.ExecuteNonQuery()
  3.         Catch ex As Exception
  4.             MessageBox.Show(ex.ToString)
  5.         End Try
...nothing was caught but there was no update made to the database either
Feb 8 '08 #4
Plater
7,872 Expert 4TB
I would suspect your WHERE clause.
Is the correct information making it into that statement?
If EnteredRecord is not a string column, you should NOT surround your values with ' (single quote)

I also see you entering a parameter into it which doesn't look like it does anything.

I would agree with whoever it was that said you should test the query out in the SQL management program
Feb 8 '08 #5
I'm pretty sure the SQL statement is right but maybe not so much with the vb code...please advise if you know better. Thanks!!

Expand|Select|Wrap|Line Numbers
  1.     Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
  2.         Dim strSqlEditRecord As String
  3.         Dim myCmd As OleDb.OleDbCommand
  4.         myCmd = Nothing
  5.         strSqlEditRecord = "UPDATE tblMain SET tblMain.Per_Hour_Quota= '" & txtQuota.Text & "' WHERE tblMain.EnteredRecord= '" & lblRecordNumber.Text & "';"
  6.         myCmd = New OleDb.OleDbCommand(strSqlEditRecord, gMDB)
  7.         myCmd.Parameters.AddWithValue("@Per_Hour_Quota", txtQuota.Text)
  8.         myCmd.CommandType = CommandType.Text
  9.         myCmd.CommandTimeout = 60
  10.         Try
  11.             myCmd.ExecuteNonQuery()
  12.         Catch ex As Exception
  13.             MessageBox.Show(ex.ToString)
  14.         End Try
  15.  
  16.         MsgBox("This record has been updated in the database.", MsgBoxStyle.Information, "Saved Record")
  17.         Clear()
  18.     End Sub
Feb 14 '08 #6
Shashi Sadasivan
1,435 Expert 1GB
strSqlEditRecord = "UPDATE tblMain SET tblMain.Per_Hour_Quota= '" & txtQuota.Text & "' WHERE tblMain.EnteredRecord= '" & lblRecordNumber.Text & "';"
myCmd = New OleDb.OleDbCommand(strSqlEditRecord, gMDB)
myCmd.Parameters.AddWithValue("@Per_Hour_Quota", txtQuota.Text)
myCmd.CommandType = CommandType.Text


Is there a @Per_Hour_Quota in your strSqlRecord?

well, the thing is it does not require a parameter to start with.
I think you can delete the following line
myCmd.Parameters.AddWithValue("@Per_Hour_Quota", txtQuota.Text)

You mentioned about an error !
Is there an exception which is being thrown?
if yes, then where and what is the the exception
Feb 14 '08 #7
strSqlEditRecord = "UPDATE tblMain SET tblMain.Per_Hour_Quota= '" & txtQuota.Text & "' WHERE tblMain.EnteredRecord= '" & lblRecordNumber.Text & "';"
myCmd = New OleDb.OleDbCommand(strSqlEditRecord, gMDB)
myCmd.Parameters.AddWithValue("@Per_Hour_Quota", txtQuota.Text)
myCmd.CommandType = CommandType.Text


Is there a @Per_Hour_Quota in your strSqlRecord?

well, the thing is it does not require a parameter to start with.
I think you can delete the following line
myCmd.Parameters.AddWithValue("@Per_Hour_Quota", txtQuota.Text)

You mentioned about an error !
Is there an exception which is being thrown?
if yes, then where and what is the the exception
if I remove myCmd.Parameters.AddWithValue("@Per_Hour_Quota", txtQuota.Text) then I get an error saying 'No value given for one or more required parameters'.
The error is thrown after Try
myCmd.ExecuteNonQuery()
Feb 14 '08 #8
kunal pawar
297 100+
when u used text always used trim function. As u said there is no error and no any records affected mean problem in ur where condition.

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

Dim strSqlEditRecord As String
Dim myCmd As OleDb.OleDbCommand
4.
myCmd = Nothing
5.
strSqlEditRecord = "UPDATE tblMain SET Per_Hour_Quota= '" & txtQuota.Text & "' WHERE EnteredRecord= '" & trim(lblRecordNumber.Text) & "';"
6.
myCmd = New OleDb.OleDbCommand(strSqlEditRecord, gMDB)
7.
myCmd.Parameters.AddWithValue("@Per_Hour_Quota", txtQuota.Text)
8.
myCmd.CommandType = CommandType.Text
9.
myCmd.CommandTimeout = 60
10.
myCmd.ExecuteNonQuery()
11.
MsgBox("This record has been updated in the database.", MsgBoxStyle.Information, "Saved Record")
12.
Clear()
13.
End Sub
Feb 15 '08 #9
when u used text always used trim function. As u said there is no error and no any records affected mean problem in ur where condition.

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

Dim strSqlEditRecord As String
Dim myCmd As OleDb.OleDbCommand
4.
myCmd = Nothing
5.
strSqlEditRecord = "UPDATE tblMain SET Per_Hour_Quota= '" & txtQuota.Text & "' WHERE EnteredRecord= '" & trim(lblRecordNumber.Text) & "';"
6.
myCmd = New OleDb.OleDbCommand(strSqlEditRecord, gMDB)
7.
myCmd.Parameters.AddWithValue("@Per_Hour_Quota", txtQuota.Text)
8.
myCmd.CommandType = CommandType.Text
9.
myCmd.CommandTimeout = 60
10.
myCmd.ExecuteNonQuery()
11.
MsgBox("This record has been updated in the database.", MsgBoxStyle.Information, "Saved Record")
12.
Clear()
13.
End Sub
Thanks for the help. I tried adding the trim function but the record did not save and did not error. Any other thoughts?
Feb 15 '08 #10
Thanks for the help. I tried adding the trim function but the record did not save and did not error. Any other thoughts?
as it turns out, the problem was simple. I misspelled a field name in the database and had to remove the single quotes from the SQL. works fine now.
Feb 20 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline...
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...
10
by: Randy Harris | last post by:
I imported records into a table, later found out that many of them had trailing spaces in one of the fields. If I'd caught it sooner, I could have trimmed the spaces before the import. This...
3
by: Greg Strong | last post by:
Hello All, Is the only solution to an update query which requires the records in a certain order to dump the records into a temp table in the required order, then do the update query? I've...
7
by: aaron.kempf | last post by:
team so i have a nice little list in sharepoint.. about 15k items i've got the simplest little join statement in access; and im trying to UPDATE the sharepoint list via an access query. so...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
11
by: ZafT | last post by:
Hi all - thanks in advance for any help. I am trying to write a simple update script. In fact, I am re-using code that I've used before (successfully) but I can't figure out why it is not...
8
by: Andi Clemens | last post by:
Hi, I want to update our DNS servers periodically with some IP addresses. But I don't know how to do this. I searched the Internet quite a while but I haven't found a good example how to do...
5
by: abhilashcashok | last post by:
hi guys, my prblem is that I cannot update sql query against MS ACCESS using C#. Everytime wen i do so, i got an exception (at runtime) as 'UPDATE syntax not correct'. I don find any error in my...
12
by: praveenkrg | last post by:
my update query is not working properly! $mgroupname=$_GET; //echo $mgroupname; ///query for checking userg_id $result=mysql_query("SELECT * FROM group WHERE userg_name ='$mgroupname'");...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.