Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

I have this code:

VB
If Len(txtSalary.Text) = 0 Or Len(txtmCover.Text) = 0 Or Len(txtMember.Text) = 0 Or Len(txtmRate.Text) = 0 Then

       MsgBox "Enter Values"

    Else
        tsql = "INSERT INTO Hpacc4(SalaryBill,Rate,Membership,Cover) " & _
               "VALUES('" & txtSalary.Text & "','" & txtmCover & "', '" & txtMember.Text & "', '" & txtmRate.Text & "')" & _
               "WHERE Scheme = '99993' AND RunMonth = '200604' AND AccCode = '110'"

       cnHPtest.Execute (tsql)

      
    End If


When I run it I get an error at my WHERE caluse, please help. I can't see where I went wrong there.
Posted
Comments
Richard MacCutchan 18-Nov-13 8:25am    
Please do not expect people to guess what the error is.
scottgp 18-Nov-13 8:27am    
What do you expect the WHERE clause to do in this insert statement?
phil.o 18-Nov-13 9:03am    
As there still has been stated:
- what is the purpose of a WHERE clause in an INSERT statement? what are you trying to do exactly?
- without the exact error message we are just bound to guess your problem
- your code is opened to SQL injection attacks ; please use parameterized queries instead of concatenating string like you do to construct your SQL query
- what is the DB type of the following columns: SalaryBill, Rate, Membership, Cover?

You can't use a WHERE clause in an Insert statement like this. You need to rethink what you are trying to accomplish and re-write. Perhaps you need to remove the WHERE altogether or perhaps you mean to insert those values into the table as well.
 
Share this answer
 
1-Your insert statement is not in the right order (Salary, Rate, Membership, Cover)
as your text boxes.
2-There is no 'Where' when doing an Insert.
3-you probably want to do an Update instead :

Update Hpacc4
Set SalaryBill = txtSalary.Text,
Rate = txtmCover.Text,
Membership=txtMember.Text,
Cover = txtmCover.text
WHERE Scheme = '99993' AND RunMonth = '200604' AND AccCode = '110'

(make sure you use the appropriate quotes in code, the above statement
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900