Wednesday, March 21, 2012

Pleas help with simple sql statement question

Hello and thanks for looking! I have this sql stament:

Dim strInsertCommand As String = "INSERT INTO CurrentDrawVar (Username, GamesBought, DateLastBuy) VALUES ('" & UserID & "', '" & gamestobuy & "', '" & Now & "')"

It works great and inserts into a database like it should. My question is where can I insert a WHERE stament into it so that I can insert this data over information that already exists in the database. FOr instance. I have a user grogo21 and in this row I want to insert gamestobuy and now. Where can i put this and is the stament below right:

WHERE Username = 'grogo21'

I tried putting it after the parenthases after the values but it doesnt work. Thanks alot!!

Hi, you need an 'UPDATE' rather than 'INERT' in this case. Firstly you should have columns to host the information you want to add to the row (gamestobuy and now), and then you can update the row using 'WHERE' clause, assigning values to the fields:

"UPDATE CurrentDrawVar SET GamesToBuy='" & gamestobuy & "', Now='" & Now & "'

WHERE UserID='"&Username&"'"

No comments:

Post a Comment