Results 1 to 5 of 5

Thread: sql insert into access database requires colon

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    366

    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???

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    366

    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?

  4. #4
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: sql insert into access database requires colon

    Quote Originally Posted by youngnoviceinneedofh View Post
    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.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    366

    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
  •  



Click Here to Expand Forum to Full Width