473,770 Members | 5,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update query not working in vb.net 2008 access?

2 New Member
Expand|Select|Wrap|Line Numbers
  1. 'Code for selecting a particular data from database
  2. '***** START *****
  3.  
  4. sSQL = "SELECT name FROM trans"
  5. cmd = New OleDbCommand(sSQL, con)
  6. Dim reader As OleDbDataReader = cmd.ExecuteReader()
  7. While reader.Read()
  8. Dim tempitem As String
  9. tempitem = reader.GetString(0)
  10.  
  11. sSQL = "SELECT itemname = '" + tempitem + "' FROM itemcount"
  12. cmd = New OleDbCommand(sSQL, con)
  13. Dim itemFound As Integer
  14. itemFound = cmd.ExecuteNonQuery()
  15. MsgBox("Temp Item : '" + tempitem + "' ")
  16.  
  17. If (itemFound = 0) Then
  18. 'INSERTION QUERY
  19. MsgBox(" In the insertion area ")
  20. Dim sSQL2 As String
  21.  
  22. 'PROBLEM AREA STARTS
  23. sSQL2 = "INSERT INTO itemcount(itemname, itemcnt) VALUES ('" + tempitem + "',1)"
  24. cmd = New OleDbCommand(sSQL, con)
  25. Dim chek As Integer = cmd.ExecuteNonQuery()
  26. If (chek > 0) Then
  27. MsgBox("Sucess")
  28. Else
  29. MsgBox("Failure")
  30. End If
  31.  
  32. 'PROBLEM AREA ENDS
  33. 'OUTPUT IS ALWAYS (FAILURE) HENCE IT NEVER GOES IN THE ELSE CONDITION
  34. Else
  35. 'UPDATE QUERY
  36. MsgBox(" In the Update area ")
  37. Dim sSQL2 As String
  38. sSQL2 = "SELECT qty FROM trans WHERE name = '" + tempitem + "'"
  39. cmd = New OleDbCommand(sSQL2, con)
  40. Dim val1 As OleDbDataReader = cmd.ExecuteReader()
  41. Dim val2 As Integer
  42. val2 = 1
  43.  
  44. Dim sSQL3 As String
  45. sSQL3 = "UPDATE itemcount SET itemcnt = '" + val2 + "' where itemname = '" + tempitem + "'"
  46. cmd = New OleDbCommand(sSQL3, con)
  47. cmd.ExecuteNonQuery()
  48. MsgBox(cmd)
  49.  
  50. End If
  51.  
  52. End While
  53. '***** END *****
  54.  
  55. reader.Close()
  56. con.Close()
  57. MsgBox("The Connection to the Database is now Closed")
  58. End Sub
  59. End Class
Help me out guys
Nov 13 '09 #1
2 3413
MrMancunian
569 Recognized Expert Contributor
Expand|Select|Wrap|Line Numbers
  1. sSQL = "SELECT itemname = '" + tempitem + "' FROM itemcount"
  2. cmd = New OleDbCommand(sSQL, con)
  3. Dim itemFound As Integer
  4. itemFound = cmd.ExecuteNonQuery()
  5. MsgBox("Temp Item : '" + tempitem + "' ")
  6.  
  7. If (itemFound = 0) Then
  8. 'INSERTION QUERY
  9. MsgBox(" In the insertion area ")
  10. Dim sSQL2 As String
  11.  
  12. 'PROBLEM AREA STARTS
  13. sSQL2 = "INSERT INTO itemcount(itemname, itemcnt) VALUES ('" + tempitem + "',1)"
  14. cmd = New OleDbCommand(sSQL, con)
  15. Dim chek As Integer = cmd.ExecuteNonQuery()
  16. If (chek > 0) Then
  17. MsgBox("Sucess")
  18. Else
  19. MsgBox("Failure")
  20. End If 
Ok, there are a few things I noticed. Concatenation in VB.NET is done with an ampersand (&), instead of plus (+). If your If...Then-statement doesn't go to the else, it means that your query ("SELECT itemname = '" + tempitem + "' FROM itemcount") doesn't affect any row. The ExecuteNonQuery returns the number of affected rows. You need to check if your query is correct (mind the concatenation). You can put a breakpoint on your query and see how it looks in runtime. If you're not sure it works, copy and paste it in a query editor in your SQL-environment.

Steven
Nov 17 '09 #2
gagandeepsngh
2 New Member
Thanks a lot that really helped me and i did solved my problem
Nov 17 '09 #3

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

Similar topics

10
3280
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 wouldn't work (nothing changed): UPDATE tblManuals SET tblManuals.PARTNUM = Trim(); Would someone please tell me how to do an update query that will trim the spaces?
7
8397
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 im joining between my access table and then sharepoint list and i get the infamous 'numeric field overflow'.
3
3451
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 the necessary records in it when testing it. I get the error "No value given for one or more required parameters." when I try to update the database. Can you tell me what am I doing wrong?
5
3242
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 'update' syntax. I can successfully run other dbase operations like insertion, deletion & all.; except Updation. But, i can successfully run the same update query in the 'sql query tab' of MS ACCESS, and is executed successfully.
3
3595
by: pks83 | last post by:
Hi I am relatively new to MSSQL.... when i am trying to fetch the data from table using this query. update ticket set escalation=activity where escalation like '2008%31' escalation and activity are both of datetime data type Values in escalation column
0
4641
by: SuzK | last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are Week Ending (date) ItemNbr (double) Sales Dollars (double) Sales Units (double) Promo (Text) -- is null or "X" AvgWklyDollars (double) AvgWklyUnits (double) I have a vba module which I thought would work, but it doesn't. I think the problem is an embedded SQL Totals Top 8 query, which doesn't...
11
6068
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know if that's what's causing the behavior or not. It seems like the Update button should at least do something. When the Edit button is clicked, the grid goes into Edit mode and the Cancel button takes the grid out of Edit mode. So, I don't get what...
3
3968
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID = ?
2
1894
by: jjb1214 | last post by:
Hi all, I've been unable to find the answer I'm looking for on the forums, so I'm asking my first-ever question. I'm building a windows forms application in Visual Basic using Visual Studio 2008. I have an Access database behind it that I'm building on. I've only been playing around with VB for a few months now, so forgive any misconceptions I may have....here's what I'm trying to accomplish: I have two tables in the database, and I need...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10225
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10053
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9867
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8880
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.