|
-
Jul 28th, 2011, 04:59 AM
#1
Thread Starter
Hyperactive Member
sql insert into access database requires colon
whats wrong with this:
Code:
Dim Cmd As New System.Data.OleDb.OleDbCommand()
con.Open()
Cmd.Connection = con
Cmd.CommandText = " INSERT INTO TblContacts ('" & Night & "') VALUES " & "('Harry') WHERE (Phone = '" & incomingtextno & "')"
Cmd.ExecuteNonQuery()
con.Close()
it stops on the line
Cmd.ExecuteNonQuery()
telling me i need a colon somewhere. however i havent needed one in the past using sql and vb.net???
-
Jul 28th, 2011, 05:07 AM
#2
Re: sql insert into access database requires colon
How can you insert with a where clause? There is nothing to compare against as you have not inserted it yet! Your sql statement is invalid.
-
Jul 28th, 2011, 06:24 AM
#3
Thread Starter
Hyperactive Member
Re: sql insert into access database requires colon
I see what you mean, but then how do you write these kinds of statements? i.e i want to edit the value in the column with title 'night' the value harry, but for a partiular record. I thought you would be able to do this.
can anyone help?
-
Jul 28th, 2011, 08:14 AM
#4
Re: sql insert into access database requires colon
 Originally Posted by youngnoviceinneedofh
I see what you mean, but then how do you write these kinds of statements? i.e i want to edit the value in the column with title 'night' the value harry, but for a partiular record. I thought you would be able to do this.
can anyone help?
You need an UPDATE Query, not an INSERT. Check out http://www.w3schools.com/sql/sql_update.asp
You should also consider using parameters in your query rather than just appending values into the text string, but your first task is to change your query to the right type.
-
Jul 28th, 2011, 11:15 AM
#5
Thread Starter
Hyperactive Member
Re: sql insert into access database requires colon
Ahh of course its an append. I have changed the line to:
Code:
Cmd.CommandText = " UPDATE tblContacts SET '" & Night & "'='" & Night + 1 & "' WHERE (Phone = '" & incomingtextno & "')"
however this doesnt work. I am trying to add 1 to the cell in the column "night" (whatever that variable is set to) where the phone number mathches. the values in the columns that i am trying to ammend are all numbers so i just want to add 1 to that number. what should i change " & Night + 1 & " to?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|