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???
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.
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?
Re: sql insert into access database requires colon
Quote:
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.
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?