- 'Code for selecting a particular data from database
-
'***** START *****
-
-
sSQL = "SELECT name FROM trans"
-
cmd = New OleDbCommand(sSQL, con)
-
Dim reader As OleDbDataReader = cmd.ExecuteReader()
-
While reader.Read()
-
Dim tempitem As String
-
tempitem = reader.GetString(0)
-
-
sSQL = "SELECT itemname = '" + tempitem + "' FROM itemcount"
-
cmd = New OleDbCommand(sSQL, con)
-
Dim itemFound As Integer
-
itemFound = cmd.ExecuteNonQuery()
-
MsgBox("Temp Item : '" + tempitem + "' ")
-
-
If (itemFound = 0) Then
-
'INSERTION QUERY
-
MsgBox(" In the insertion area ")
-
Dim sSQL2 As String
-
-
'PROBLEM AREA STARTS
-
sSQL2 = "INSERT INTO itemcount(itemname, itemcnt) VALUES ('" + tempitem + "',1)"
-
cmd = New OleDbCommand(sSQL, con)
-
Dim chek As Integer = cmd.ExecuteNonQuery()
-
If (chek > 0) Then
-
MsgBox("Sucess")
-
Else
-
MsgBox("Failure")
-
End If
-
-
'PROBLEM AREA ENDS
-
'OUTPUT IS ALWAYS (FAILURE) HENCE IT NEVER GOES IN THE ELSE CONDITION
-
Else
-
'UPDATE QUERY
-
MsgBox(" In the Update area ")
-
Dim sSQL2 As String
-
sSQL2 = "SELECT qty FROM trans WHERE name = '" + tempitem + "'"
-
cmd = New OleDbCommand(sSQL2, con)
-
Dim val1 As OleDbDataReader = cmd.ExecuteReader()
-
Dim val2 As Integer
-
val2 = 1
-
-
Dim sSQL3 As String
-
sSQL3 = "UPDATE itemcount SET itemcnt = '" + val2 + "' where itemname = '" + tempitem + "'"
-
cmd = New OleDbCommand(sSQL3, con)
-
cmd.ExecuteNonQuery()
-
MsgBox(cmd)
-
-
End If
-
-
End While
-
'***** END *****
-
-
reader.Close()
-
con.Close()
-
MsgBox("The Connection to the Database is now Closed")
-
End Sub
-
End Class
Help me out guys
2 3413 - sSQL = "SELECT itemname = '" + tempitem + "' FROM itemcount"
-
cmd = New OleDbCommand(sSQL, con)
-
Dim itemFound As Integer
-
itemFound = cmd.ExecuteNonQuery()
-
MsgBox("Temp Item : '" + tempitem + "' ")
-
-
If (itemFound = 0) Then
-
'INSERTION QUERY
-
MsgBox(" In the insertion area ")
-
Dim sSQL2 As String
-
-
'PROBLEM AREA STARTS
-
sSQL2 = "INSERT INTO itemcount(itemname, itemcnt) VALUES ('" + tempitem + "',1)"
-
cmd = New OleDbCommand(sSQL, con)
-
Dim chek As Integer = cmd.ExecuteNonQuery()
-
If (chek > 0) Then
-
MsgBox("Sucess")
-
Else
-
MsgBox("Failure")
-
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
Thanks a lot that really helped me and i did solved my problem
Sign in to post your reply or Sign up for a free account.
Similar topics |
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?
|
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'.
|
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?
|
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.
|
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
| |
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...
|
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...
|
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 = ?
|
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...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |