473,403 Members | 2,293 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,403 software developers and data experts.

Problems with update sql statemnt in vb6

12
I have a table called SupplierInfor with tables:
SupplierID - Autonumber
Date - date
SupplierName - Text
SupplierAddress - text
Telephone - Number
email - text
Town - text
country - text
I want to update all records in this table where supplierID is a certain number. The code i have is as below:
Expand|Select|Wrap|Line Numbers
  1. dim strSQL as string
  2. strSQL = "UPDATE SupplierInfor SET " & _
  3.     "[Date]='" & txtDate.Text & "', " & _
  4.     "[SupplierName]='" & txtSuppName.Text & "', " & _
  5.     "[SupplierAddress]='" & txtSuppAddress.Text & "', " & _
  6.     "[Telephone]='" & txtTelephone.Text & "', " & _
  7.     "[email]='" & txtEmail.Text & "', " & _
  8.     "[Town]=" & cboTown.Text & ", " & _
  9.     "[Country]=" & cboCountry.Text & " WHERE [SupplierID]='" & Val(txtSuppID.Text) & "'"
  10.  
  11.    Cn.Execute strSQL
When i run the code i get the error message "no value given for one or more required parameters" Am using vb6 and ADO connection to MS Access 2000.
What is the problem with my code? PLease help me and i will appreciate any assistance.
Sep 30 '08 #1
13 6547
QVeen72
1,445 Expert 1GB
Hi,

Dates need to be enclosed with a Hash:
And since you say Supplier ID is Autonumber and Telephone is Numeric, no need to Wrap it with Single quotes:

Expand|Select|Wrap|Line Numbers
  1. dim strSQL as string
  2. strSQL = "UPDATE SupplierInfor SET " & _
  3.     "[Date]=#" & txtDate.Text & "#,  " & _
  4.     "[SupplierName]='" & txtSuppName.Text & "', " & _
  5.     "[SupplierAddress]='" & txtSuppAddress.Text & "', " & _
  6.     "[Telephone]=" & Val(txtTelephone.Text) & ", " & _
  7.     "[email]='" & txtEmail.Text & "', " & _
  8.     "[Town]='" & cboTown.Text & "', " & _
  9.     "[Country]='" & cboCountry.Text & "' WHERE [SupplierID]=" & Val(txtSuppID.Text) 
  10.  
Regards
Veena
Sep 30 '08 #2
depash
12
Thanks alot Veena
It worked and now am so grateful for that. But their is another problem, when i try to delete a record in the same table using the code below, it runs without any error but does not delete any record even if i keep on clicking the delete button. Please look at the code and help me with the area of the problem.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdDelete_Click()
  2. Dim kuiz As String
  3. kuiz = MsgBox("Are you sure you want to DELETE the current record?", vbYesNo + vbQuestion, "Confirm delete...")
  4. If kuiz = vbYes Then
  5. R3.Open "SELECT * FROM SupplierInfor where SupplierName='" & Trim(txtSuppName.Text) & "'", Cn, adOpenDynamic, adLockBatchOptimistic
  6.     If Not R3.EOF Then
  7.         R3.Delete
  8.     End If
  9. R3.Close
  10. Set R3 = Nothing
  11. End If
  12. End Sub
Thanks again for your help.
Oct 1 '08 #3
QVeen72
1,445 Expert 1GB
Hi,

No Need TO Open a Record and Delete.. Just Run a Delete Query:

Expand|Select|Wrap|Line Numbers
  1. Cn.Execute "Delete FROM SupplierInfor where SupplierName='" & Trim(txtSuppName.Text) & "'"
  2.  
Regards
Veena
Oct 1 '08 #4
depash
12
Hi Veena,
Thanks for this help, just imagine the delete code just works fine, Thanks coz i was stuck in this. I just don't seem to get someting clear about the UPDATE SQL. Am trying to update a table called ITEM_MASTER_TB WITH THE FOLLOWING FIELDS:
ID - Autonumber
Bardcode - text
Description - text
Category - text
Units - text
Priceperunit - Currency
Quantity - Number
Totalcost - Curency
SupplierName - text
DateOfSupply - date
VAtPer - currency

the code for updating the table is as follows, please forgive me for asking too many questions its only that am not good in SQL.

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.    strSQL = "UPDATE ITEM_MASTER_TBL SET " & _
  3.     "[DESCRIPTION]='" & txtItemDescription.Text & "', " & _
  4.     "[CATEGORY]='" & cboCategory.Text & "', " & _
  5.     "[UNITS]='" & cboUnits.Text & "', " & _
  6.     "[PRICEPERUNIT]='" & txtPricePerUnit.Text & "', " & _
  7.     "[QUANTITY]=" & txtQuantity.Text & ", " & _
  8.     "[TOTALCOST]='" & txtCost.Text & "', " & _
  9.     "[DATEOFSUPPLY]='" & txtDate.Text & "', " & _
  10.     "[VATPER]='" & txtVATPER.Text & "' WHERE [BARCODE]=" & txtBarcode.Text & ""
  11.    Cn.Execute strSQL
the code returns 'DATA TYPE MISMATCH IN CRITERIA EXPRESSION'. Just maybe it is the single quotes have put in wrong place.
Oct 1 '08 #5
depash
12
Hi Veena,
Sory I just got the problem, its my ignorance the same problem again. I forgot HASH for date column and single quote for txtBarcode.text. I have done the corrections and its OK. Thanks Bro.
Oct 1 '08 #6
depash
12
Hi Veena,
This i know is the logic maybe. In the same project am working on, i want to insert several records in a table using the INSERT INTO SQL. The records i want to insert are in a MSflexgrid that i have populated with data. My coden to do this is as below:
Expand|Select|Wrap|Line Numbers
  1. Dim q As Integer
  2.     With Me.MSFlexPOS
  3.     For q = 1 To (.Rows - 1)
  4.  
  5.         Cn.Execute "INSERT INTO POS_TBL(INVNO,INVDATE,BARCODE,DESCRIPTION,CATEGORY,UNITS,COST,QTY,VATPER,STOTAL,VATAMT,LINETOTAL)VALUES(" & _
  6.             Me.TXTINVNUMBER.Caption & ",#" & _
  7.             Me.TXTINVDATE.Caption & "#,'" & _
  8.                 .TextMatrix(q, 1) & "','" & _
  9.                 .TextMatrix(q, 2) & "','" & _
  10.                 .TextMatrix(q, 3) & "','" & _
  11.                 .TextMatrix(q, 4) & "'," & _
  12.                 .TextMatrix(q, 5) & "," & _
  13.                 .TextMatrix(q, 6) & "," & _
  14.                 .TextMatrix(q, 7) & "," & _
  15.             Val(.TextMatrix(q, 8)) & "," & _
  16.             Val(.TextMatrix(q, 9)) & "," & _
  17.             Val(.TextMatrix(q, 10)) & ")"
  18.         Next q
  19.     End With
The problem is that it can't loop through the records while inserting them, but if i do away with the for statement, it works but inserts only the first record in the msflexgrid. Do you have an idea how to insert several records while looping in a table. Your help is invaluable.
Oct 1 '08 #7
QVeen72
1,445 Expert 1GB
Hi,

Ms.Veena here,
Query Seems to be OKay.. Let me know what is your Database and What is the Provider in Connection String.. Is there any PrimaryKey for the Table..?
If you have a PK and If you are trying to Insert mutiple Records for same PK, then records cannot be Inserted..
If there is no PK, then Try using Begin and Commit Trans,,
Some thing like this :

Expand|Select|Wrap|Line Numbers
  1. Cn.BeginTrans
  2. Cn.Execute "<MySQL Statement>"
  3. Cn.CommitTrans
  4.  
REgards
Veena
Oct 2 '08 #8
depash
12
Thanks Ms Veena,
My Database is MS access 2000 called POS_DB and the connection string is:
Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Point-Of-Sale\POS_DB.MDB; Persist Security Info=False"
Cn.CursorLocation = adUseClient
The table am inserting multiple records has a primary key i.e. ID - Autonumber
Thanks in advance.
Oct 2 '08 #9
QVeen72
1,445 Expert 1GB
Hi,

Did you try using Begin and committrans...?
Also Try to Keep a BreakPoint at Cn.Execute and immediately after executing check if the recs are inserted in the Accessdb.. Check after every insert..
It takes a Few Seconds in Access To Get re-freshed..

But I guess, You can Open a Recset To add data..
Thats what everyone normally follow..
To Delete /Edit Records use "Execute <SQL>"
To Add Records Open a RecordSet....


Regards
Veena
Oct 2 '08 #10
depash
12
Hi,

Sorry, i didn't try coz i have never used Begin or Committrans in vb6. Actually i do not know where to code it maybe you could sort me out on this.Another clarification from you please, When i want to use the Recordset instead of the Execute SQL, is it a must i have a ADO control on the form for it to work? Do you have an example of using the Recordset? Much Gratitude
Oct 2 '08 #11
QVeen72
1,445 Expert 1GB
Hi,

Not Necessary to have DATA control to open recordset...
You can use ADO Objects...

Some thing Like This :
assuming you connection is Open..
Expand|Select|Wrap|Line Numbers
  1. Dim RST As New ADODB.Recordset
  2. RST.Open "Select * From MyTable",Cn,adOpenDynamic, adLockOptimistic
  3. RST.AddNew
  4. RST("MyCol1") = Text1.Text
  5. RST("MyCol2") = Text2.Text
  6. RST("MyCol3") = Text3.Text
  7. RST.Update
  8. RST.Close
  9.  
You Can use the Same Code To Loop through FlexGrid Rows..(Just your TextMatrix Row will change)

Regards
Veena
Oct 3 '08 #12
depash
12
Let me give it a try and i hope this sorts me out. Thanks alot for your invaluable assistance you've provided. You remain in my memory. Incase am stuck, i'll seek your help. Nice time.
Oct 3 '08 #13
depash
12
Am sorry i was not able to work through your suggestion. I wanted to insert several records into a table while looping throuth the records in a msflexgrid with the code below:


1. Dim q As Integer
2. With Me.MSFlexPOS
3. For q = 1 To (.Rows - 1)
4.
5. Cn.Execute "INSERT INTO POS_TBL(INVNO,INVDATE,BARCODE,DESCRIPTION,CATEGORY ,UNITS,COST,QTY,VATPER,STOTAL,VATAMT,LINETOTAL)VAL UES(" & _
6. Me.TXTINVNUMBER.Caption & ",#" & _
7. Me.TXTINVDATE.Caption & "#,'" & _
8. .TextMatrix(q, 1) & "','" & _
9. .TextMatrix(q, 2) & "','" & _
10. .TextMatrix(q, 3) & "','" & _
11. .TextMatrix(q, 4) & "'," & _
12. .TextMatrix(q, 5) & "," & _
13. .TextMatrix(q, 6) & "," & _
14. .TextMatrix(q, 7) & "," & _
15. Val(.TextMatrix(q, 8)) & "," & _
16. Val(.TextMatrix(q, 9)) & "," & _
17. Val(.TextMatrix(q, 10)) & ")"
18. Next q
19. End With

but the program generates a syntax error in the insert into statement. The table has a primaly key which is autonumber. Please sort me out coz am seriously stuck. Consider an elaborate answer please.
Thanks in advance
Oct 8 '08 #14

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

Similar topics

3
by: | last post by:
Hello, Sorry to ask what is probably a simple answer, but I am having problems updating a table/database from a PHP/ PHTML file. I can Read From the Table, I can Insert into Table/Database, But...
0
by: ccuthbert | last post by:
I have a MCMS 2002 site that we recently had several hotfixes installed. After installing the hotfixes, both AOL users and Earthlink users experience tha same problem, namely that intermittently...
3
by: daveland | last post by:
I am working on some JavaScript that dynamically adds rows to a table in response to a button click. A new row does appear on the screen when the button is clicked. However, that table to which a...
1
by: Rolan | last post by:
Having tried various permutations of Before Update and well for that matter, After Update, OnExit, OnEnter, etc. and also Locked controls, I'm still unable to obtain the intended results. There are...
5
by: Dan Smith | last post by:
When I try to create a new C# Web Reference in Visual Studio 2003, I get an error message "The proxy settings on this computer are not configured correctly for web discovery. ..." This web...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
12
by: Bruce One | last post by:
For all the ORM i have searched around, I have always found two big problems: 1) To update or delete a set of records you must first bring it to memory. If you are inside a loop and have to do it...
9
by: Monroeski | last post by:
I have a form that has two subforms on it - one of them is continuous and lists a bunch of data about a given service's performance measures, while the other is a single view form where the user...
2
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in...
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: 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
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
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
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
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...

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.