Syntax error in INSERT INTO statement.

this is my new problem in vb

Page 1 of 1

14 Replies - 4541 Views - Last Post: 11 November 2010 - 07:32 AM Rate Topic: -----

#1 tina G  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 52
  • Joined: 11-February 10

Syntax error in INSERT INTO statement.

Posted 07 April 2010 - 08:08 PM

Imports System.Data.OleDb
Public Class Form1
#Region "Declaration"
    Dim Conn As OleDbConnection
    Dim Comm As OleDbCommand
    Dim OleA As OleDbDataAdapter
    Dim DSSearch As New DataSet
    Dim DS As New DataSet
    Dim DsA
    Dim SQL As String
    Dim Drow As DataRow
#End Region

    Private Sub MyConnect()
        Try
            Conn = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=ICON.mdb")
            Conn.Open()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DisClearTxt()
        ShowGrid()
    End Sub
    Private Sub DisClearTxt()
        TxtStNo.Clear()
        TxtAddress.Clear()
        TxtLName.Clear()
        TxtFName.Enabled = False
        TxtMName.Enabled = True
        TxtAddress.Enabled = False
        TxtLandLineNo.Enabled = False
        TxtCellNo.Enabled = False
        TxtEmail.Enabled = False
        TxtCellNo.Enabled = False
        TxtNationality.Enabled = False
        TxtBday.Enabled = False
        CbxGender.Enabled = False
        CbxStatus.Enabled = False

    End Sub
    Private Sub EnableTxt()
        TxtFName.Enabled = True
        TxtMName.Enabled = True
        TxtLName.Enabled = True
        TxtAddress.Enabled = True
        TxtLandLineNo.Enabled = True
        TxtCellNo.Enabled = True
        TxtEmail.Enabled = True
        TxtCellNo.Enabled = True
        TxtNationality.Enabled = True
        TxtBday.Enabled = True
        CbxGender.Enabled = True
        CbxStatus.Enabled = True
        TxtStNo.Focus()
    End Sub
    Private Sub ShowGrid()
        MyConnect()
        SQL = "Select * From tblMembers"
        Comm = New OleDbCommand(SQL, Conn)
        OleA = New OleDbDataAdapter(Comm)
        DS.Clear()
        OleA.Fill(DS, "tblMembers")
        Dgvshow.DataSource = DS
        Dgvshow.DataMember = "tblMembers"
        Conn.Close()


    End Sub

    Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
        If BtnAdd.Text = "&Add" Then
            BtnAdd.Text = "&Save"
            EnableTxt()
        Else
            MyConnect()
            SQL = "INSERT INTO tblMembers(StNo,FName,LName,MName,Address,LandLineNo,CellNo,Email,Gender,Nationality,Bday,Status) Values ('" & TxtStNo.Text & "', '" & TxtFName.Text & "','" & TxtMName.Text & "','" & TxtLName.Text & "','" & TxtAddress.Text & "'," & TxtLandLineNo.Text & "," & TxtCellNo.Text & ",'" & TxtEmail.Text & "'," & CbxGender.Text & ",'" & TxtNationality.Text & "'," & TxtBday.Text & ",'" & CbxStatus.Text & "')"
            Comm = New OleDbCommand(SQL, Conn)
            Comm.ExecuteNonQuery()
            MsgBox("Record saved!")
            ShowGrid()
            Conn.Close()
            BtnAdd.Text = "&Add"
            DisClearTxt()
        End If
    End Sub
    Private Function SearchRecord() As Boolean
        Dim StrStNo As String = InputBox("Input Student Number", "Record Search")
        MyConnect()
        SQL = "Select StNo,FName,MName,LName,Address,LandLineNo,CellNo,Email,Gender,Status,Bday,Nationality FROM tblMEmbers WHERE StNo = '" & StrStNo & "'"
        Comm = New OleDbCommand(SQL, Conn)
        OleA = New OleDbDataAdapter(Comm)
        DSSearch.Clear()
        OleA.Fill(DSSearch, "tblMembers")
        If DSSearch.Tables(0).Rows.Count > 0 Then
            Drow = DSSearch.Tables("tblMembers").Rows(0)
            TxtStNo.Text = Drow("StNo")
            TxtFName.Text = Drow("FName")
            TxtMName.Text = Drow("MName")
            TxtLName.Text = Drow("LName")
            TxtAddress.Text = Drow("Address")
            TxtLandLineNo.Text = Drow("LandLineNo")
            TxtCellNo.Text = Drow("CellNo")
            TxtNationality.Text = Drow("Nationality")
            TxtBday.Text = Drow("Bday")
            CbxGender.Text = ("Gender")
            CbxStatus.Text = ("Status")
            SearchRecord = True
        Else
            SearchRecord = False
        End If
    End Function

    Private Sub BtnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEdit.Click
        If BtnEdit.Text = "&Edit" Then
            If SearchRecord() Then
                BtnEdit.Text = "&Update"
                EnableTxt()
            Else
                MsgBox("Record does not exist! duh?")
            End If
        Else
            MyConnect()
            SQL = "Update tblsMembers SET StNo ='" & TxtStNo.Text & "',FName ='" & TxtFName.Text & "',MName = '" & TxtLName.Text & "',Gender = '" & CbxGender.Text & "',Status = '" & CbxStatus.Text & "', Address = '" & TxtAddress.Text & "',LandLineNo =" & TxtLandLineNo.Text & ", CellNo =" & TxtCellNo.Text & ",Bday = " & TxtBday.Text & ",Nationality ='" & TxtNationality.Text & "',Email='" & TxtEmail.Text & "'"
            Comm = New OleDbCommand(SQL, Conn)
            Comm.ExecuteNonQuery()
            MsgBox("Record Updated!")
            BtnEdit.Text = "&Edit"
            DisClearTxt()
            Conn.Close()
            ShowGrid()
        End If
    End Sub

    Private Sub BtnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDelete.Click
        If SearchRecord() Then
            If MsgBox("Delete This Record?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                MyConnect()
                SQL = "Delete FROM tblMembers Where Stno = '" & TxtStNo.Text & "'"
                Comm = New OleDbCommand(SQL, Conn)
                Comm.ExecuteNonQuery()
                MsgBox("Record Deleted!")
                Conn.Close()
                ShowGrid()
                DisClearTxt()
            End If
        End If
    End Sub
    Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click
        Me.Close()
    End Sub
End Class
 

so, this is my codes
The error occurs when I execute the program and this part will be affected:
 Comm.ExecuteNonQuery() 
and it says that "SYNTAX ERROR INSERT INTO STATEMENT"
what should i do here?
I am stuck help me please?
thanks..^^

Is This A Good Question/Topic? 0
  • +

Replies To: Syntax error in INSERT INTO statement.

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Syntax error in INSERT INTO statement.

Posted 07 April 2010 - 08:22 PM

Moved to VB.NET
Was This Post Helpful? 0
  • +
  • -

#3 keakTheGEEK  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 108
  • View blog
  • Posts: 344
  • Joined: 23-February 10

Re: Syntax error in INSERT INTO statement.

Posted 07 April 2010 - 08:30 PM

It's probably something to do with single quotes missing when building your insert string. There's a much better way to build that insert statement using parameters and addwithvalue method. This Link shows an example of a way to do that in both VB .NET and C#

This post has been edited by keakTheGEEK: 07 April 2010 - 08:30 PM

Was This Post Helpful? 0
  • +
  • -

#4 tina G  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 52
  • Joined: 11-February 10

Re: Syntax error in INSERT INTO statement.

Posted 07 April 2010 - 09:45 PM

Imports System.Data.OleDb
Public Class Form1
#Region "Declaration"
    Dim Conn As OleDbConnection
    Dim Comm As OleDbCommand
    Dim OleA As OleDbDataAdapter
    Dim DSSearch As New DataSet
    Dim DS As New DataSet
    Dim DsA
    Dim SQL As String
    Dim Drow As DataRow
#End Region

    Private Sub MyConnect()
        Try
            Conn = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=ICON.mdb")
            Conn.Open()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DisClearTxt()
        ShowGrid()
    End Sub
    Private Sub DisClearTxt()
        TxtStNo.Clear()
        TxtAddress.Clear()
        TxtLName.Clear()
        TxtFName.Enabled = False
        TxtMName.Enabled = True
        TxtAddress.Enabled = False
        TxtLandLineNo.Enabled = False
        TxtCellNo.Enabled = False
        TxtEmail.Enabled = False
        TxtCellNo.Enabled = False
        TxtNationality.Enabled = False
        TxtBday.Enabled = False
        CbxGender.Enabled = False
        CbxStatus.Enabled = False

    End Sub
    Private Sub EnableTxt()
        TxtFName.Enabled = True
        TxtMName.Enabled = True
        TxtLName.Enabled = True
        TxtAddress.Enabled = True
        TxtLandLineNo.Enabled = True
        TxtCellNo.Enabled = True
        TxtEmail.Enabled = True
        TxtCellNo.Enabled = True
        TxtNationality.Enabled = True
        TxtBday.Enabled = True
        CbxGender.Enabled = True
        CbxStatus.Enabled = True
        TxtStNo.Focus()
    End Sub
    Private Sub ShowGrid()
        MyConnect()
        SQL = "Select * From tblMembers"
        Comm = New OleDbCommand(SQL, Conn)
        OleA = New OleDbDataAdapter(Comm)
        DS.Clear()
        OleA.Fill(DS, "tblMembers")
        Dgvshow.DataSource = DS
        Dgvshow.DataMember = "tblMembers"
        Conn.Close()


    End Sub

    Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
        If BtnAdd.Text = "&Add" Then
            BtnAdd.Text = "&Save"
            EnableTxt()
        Else
            MyConnect()
            SQL = "INSERT INTO tblMembers(StNo,FName,LName,MName,Address,LandLineNo,CellNo,Email,Gender,Nationality,Bday,Status) Values ('" & TxtStNo.Text & "', '" & TxtFName.Text & "','" & TxtMName.Text & "','" & TxtLName.Text & "','" & TxtAddress.Text & "'," & TxtLandLineNo.Text & "," & TxtCellNo.Text & ",'" & TxtEmail.Text & "'," & CbxGender.Text & ",'" & TxtNationality.Text & "'," & TxtBday.Text & ",'" & CbxStatus.Text & "')"
            Comm = New OleDbCommand(SQL, Conn)
            Comm.ExecuteNonQuery()
            MsgBox("Record saved!")
            ShowGrid()
            Conn.Close()
            BtnAdd.Text = "&Add"
            DisClearTxt()
        End If
    End Sub
    Private Function SearchRecord() As Boolean
        Dim StrStNo As String = InputBox("Input Student Number", "Record Search")
        MyConnect()
        SQL = "Select StNo,FName,MName,LName,Address,LandLineNo,CellNo,Email,Gender,Status,Bday,Nationality FROM tblMEmbers WHERE StNo = '" & StrStNo & "'"
        Comm = New OleDbCommand(SQL, Conn)
        OleA = New OleDbDataAdapter(Comm)
        DSSearch.Clear()
        OleA.Fill(DSSearch, "tblMembers")
        If DSSearch.Tables(0).Rows.Count > 0 Then
            Drow = DSSearch.Tables("tblMembers").Rows(0)
            TxtStNo.Text = Drow("StNo")
            TxtFName.Text = Drow("FName")
            TxtMName.Text = Drow("MName")
            TxtLName.Text = Drow("LName")
            TxtAddress.Text = Drow("Address")
            TxtLandLineNo.Text = Drow("LandLineNo")
            TxtCellNo.Text = Drow("CellNo")
            TxtNationality.Text = Drow("Nationality")
            TxtBday.Text = Drow("Bday")
            CbxGender.Text = ("Gender")
            CbxStatus.Text = ("Status")
            SearchRecord = True
        Else
            SearchRecord = False
        End If
    End Function

    Private Sub BtnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEdit.Click
        If BtnEdit.Text = "&Edit" Then
            If SearchRecord() Then
                BtnEdit.Text = "&Update"
                EnableTxt()
            Else
                MsgBox("Record does not exist! duh?")
            End If
        Else
            MyConnect()
            SQL = "Update tblsMembers SET StNo ='" & TxtStNo.Text & "',FName ='" & TxtFName.Text & "',MName = '" & TxtLName.Text & "',Gender = '" & CbxGender.Text & "',Status = '" & CbxStatus.Text & "', Address = '" & TxtAddress.Text & "',LandLineNo =" & TxtLandLineNo.Text & ", CellNo =" & TxtCellNo.Text & ",Bday = " & TxtBday.Text & ",Nationality ='" & TxtNationality.Text & "',Email='" & TxtEmail.Text & "'"
            Comm = New OleDbCommand(SQL, Conn)
            Comm.ExecuteNonQuery()
            MsgBox("Record Updated!")
            BtnEdit.Text = "&Edit"
            DisClearTxt()
            Conn.Close()
            ShowGrid()
        End If
    End Sub

    Private Sub BtnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDelete.Click
        If SearchRecord() Then
            If MsgBox("Delete This Record?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                MyConnect()
                SQL = "Delete FROM tblMembers Where Stno = '" & TxtStNo.Text & "'"
                Comm = New OleDbCommand(SQL, Conn)
                Comm.ExecuteNonQuery()
                MsgBox("Record Deleted!")
                Conn.Close()
                ShowGrid()
                DisClearTxt()
            End If
        End If
    End Sub
    Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click
        Me.Close()
    End Sub
End Class



so, this is my codes
The error occurs when I execute the program and this part will be affected:
 Comm.ExecuteNonQuery() 

and it says that "SYNTAX ERROR INSERT INTO STATEMENT"
what should i do here?
I am stuck help me please?
thanks..
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Syntax error in INSERT INTO statement.

Posted 07 April 2010 - 09:48 PM

Come on now, did you think opening a duplicate thread would get you help faster?

Please don't create duplicates
Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1726
  • View blog
  • Posts: 5,704
  • Joined: 25-September 09

Re: Syntax error in INSERT INTO statement.

Posted 08 April 2010 - 05:12 AM

What data are you putting into Gender? I assume M / F or Male / Female. If so, you need to enclose that in ' '

Also, you have LName and MName reversed on the values side.

Dates either need to be enclosed with ' ' for SQLServer or # # for Access

If the phone numbers contain anything other than a digit, you will need to put ' ' around them otherwise any - will produce a calculated result against the numbers.
Was This Post Helpful? 0
  • +
  • -

#7 Guest_Yuri Gagari*


Reputation:

Re: Syntax error in INSERT INTO statement.

Posted 14 May 2010 - 04:01 PM

ui = ("Insert into UserInfo values (salutation='" + comboBox1.SelectedItem.ToString() + "',UserName='" + textBox1.Text.ToString() + "',Password='" + textBox2.Text.ToString() + "',FirstName='" + textBox4.Text.ToString() + "',LastName='" + textBox5.Text.ToString() + "',Gender='"+gender+"',DOB='" + dateTimePicker1.Text.ToString() + "',PostalAddress='" + textBox7.Text.ToString() + "',suburb='" + textBox8.Text.ToString() + "',city='" + textBox6.Text.ToString() + "',state='" + textBox9.Text.ToString() + "',postalcode='" + textBox10.Text.ToString() + "',telephone='" + textBox11.Text.ToString() + "',mobile='" + textBox12.Text.ToString() + "')");


same ExecuteNonQuery error
kindly help ..
Was This Post Helpful? 0

#8 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1726
  • View blog
  • Posts: 5,704
  • Joined: 25-September 09

Re: Syntax error in INSERT INTO statement.

Posted 14 May 2010 - 04:16 PM

Try this format
INSERT INTO MyTable (Field1, Field2) VALUES ('field1 value', 'Field2 value')


You are trying to use 2 different statements combined

You are trying to do this

INSERT INTO MyTable Values (field1 = 'field1 value', field2 = 'field2 value')


This is closer to an update statement where you would use:

Update MyTable SET field1 = 'field1 value', field2 = 'field2 value' WHERE tableID = 1


Also, when using a lot of fields, it would be a lot easier to follow your statement if you used parameters. Plus you wouldn't have to append all those controls
Something like
INSERT INTO UserInfo (salutation, UserName, Password) VALUES (@salutation, @UserName, @Password)
cmd.parameters.addwithvalue("@salutation", combobox1.selectedItem.Tostring())
cmd.parameters.addwithvalue("@UserName", textbox1.Text)
cmd.parameters.addwithvalue("@Password", TextBox2.Text)
'Where cmd is whatever you used as your command.


Was This Post Helpful? 1
  • +
  • -

#9 Guest_Yuri Gagari*


Reputation:

Re: Syntax error in INSERT INTO statement.

Posted 15 May 2010 - 12:26 AM

thanks for the reply to my post i will surely try and come bak to you .. really appreciate .. :)
Was This Post Helpful? 0

#10 Guest_Yuri Gagari*


Reputation:

Re: Syntax error in INSERT INTO statement.

Posted 15 May 2010 - 08:07 AM

hey,

as per ur advise i tried changing da the ccode as follows:-

ui = ("insert into Userinfo (salutation,UserName,Password,FirstName, LastName, Gender, DOB, PostalAddress, Suburb, City, State, PostalCode, Telephone, Mobile)value(@Salutation, @UserName, @Password, @FirstName, @LastName, @Gender, @DOB, @PostalAddress, @Suburb, @City, @State,@PostalCode, @Telephone, @Mobile)");
            
            SqlCommand com=new SqlCommand(ui,con);
           
            com.Parameters.AddWithValue("@Salutation",comboBox1.SelectedItem.ToString() );
            com.Parameters.AddWithValue("@UserName",textBox1.Text.ToString() );
            com.Parameters.AddWithValue("@Password", textBox2.Text.ToString());
            com.Parameters.AddWithValue("@FirstName", textBox3.Text.ToString());
            com.Parameters.AddWithValue("@LastName", textBox2.Text.ToString());
            com.Parameters.AddWithValue("@Gender", gender);
            com.Parameters.AddWithValue("@DOB", dateTimePicker1.Text.ToString());
            com.Parameters.AddWithValue("@PostalAddress",textBox7.Text.ToString() );
            com.Parameters.AddWithValue("@Suburb",textBox8.Text.ToString() );
            com.Parameters.AddWithValue("@City", textBox6.Text.ToString());
            com.Parameters.AddWithValue("@State",textBox9.Text.ToString() );
            com.Parameters.AddWithValue("@PostalCode", textBox10.Text.ToString());
            com.Parameters.AddWithValue("@Telephone",textBox11.Text.ToString() );
            com.Parameters.AddWithValue("@Mobile", textBox12.Text.ToString());
            
            com.ExecuteNonQuery();
            
            con.Close();



however i m receiving the same nonquery error .. kindly advise,

regards,

yuri.

This post has been edited by JackOfAllTrades: 11 November 2010 - 12:08 PM
Reason for edit:: Added code tags

Was This Post Helpful? 0

#11 Guest_Yuri Gagari*


Reputation:

Re: Syntax error in INSERT INTO statement.

Posted 15 May 2010 - 08:13 AM

and sorry the above code is in C#.Net 2008 and backend Sql Server 2008 :S
Was This Post Helpful? 0

#12 kojima100  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 66
  • Joined: 10-November 10

Re: Syntax error in INSERT INTO statement.

Posted 10 November 2010 - 04:28 AM

I appear to be having the same problem when running this code
SqlQuery = "INSERT INTO UserInfo ('[UserName]', '[Password]', '[FirstName]', '[LastName]', '[DateJoiuned]', '[IsAdmin]' VALUES (@UserName, @Password, @FirstName, @LastName, @DateJoined, @IsAdmin)"


                       Dim SqlAppendCmd As New OleDbCommand(SqlQuery, Connection)

                       With SqlAppendCmd.Parameters

                         .AddWithValue("@UserName", TxtUserName.Text)
                         .AddWithValue("@[Password]", TxtPassword.Text)
                         .AddWithValue("@FirstName", TxtFirstName.Text)
                         .AddWithValue("@LastName", TxtSecondName.Text)
                         .AddWithValue("@DateJoined", System.Convert.ToDateTime(My.Computer.Clock.LocalTime.Date).ToOADate)
                         .AddWithValue("@IsAdmin", ChkIsAdmin.Checked())
                                            
                                        End With
                          'The error happens when this line executes.
                             Dim DataCheck = SqlAppendCmd.ExecuteNonQuery()


I get an error message telling me that their's a syntax error in the INSERT INTO query.
Any help i can get with this problem would be greatly appreciated.

This post has been edited by kojima100: 10 November 2010 - 04:33 AM

Was This Post Helpful? 0
  • +
  • -

#13 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1726
  • View blog
  • Posts: 5,704
  • Joined: 25-September 09

Re: Syntax error in INSERT INTO statement.

Posted 10 November 2010 - 08:11 AM

The format is:
INSERT INTO Table (field, field, field) VALUES ('value', 'value', 'value')

Do not put apostrophies around the field names and make sure your paranthesis are correct. Also, the apostrophe's around the values are for strings not numbers.

EDIT:
The [] brackets are ok around all fields.

After you fix that, you will get another area unless you actually spelled the field "datejoiuned"
EDIT AGAIN:
The parameter @Password needs to be the same in the parameters and does not need the [] as it is a parameter.

This post has been edited by CharlieMay: 10 November 2010 - 08:15 AM

Was This Post Helpful? 0
  • +
  • -

#14 kojima100  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 66
  • Joined: 10-November 10

Re: Syntax error in INSERT INTO statement.

Posted 11 November 2010 - 06:02 AM

Thanks Charlie, I've changed the code like you said but I appear to be getting the same message. Is there something else I should do?

 SqlQuery = "INSERT INTO UserInfo ([UserName], [Password], [FirstName], [LastName], [DateJoined], [IsAdmin] VALUES ('@UserName', '@Password', '@FirstName', '@LastName', @DateJoined, @IsAdmin)"


            Dim SqlAppendCmd As New OleDbCommand(SqlQuery, Connection)

                     With SqlAppendCmd.Parameters

                       .AddWithValue("@UserName", TxtUserName.Text)
                       .AddWithValue("@Password", TxtPassword.Text)
                       .AddWithValue("@FirstName", TxtFirstName.Text)
                       .AddWithValue("@LastName", TxtSecondName.Text)
                       .AddWithValue("@DateJoined", System.Convert.ToDateTime(My.Computer.Clock.LocalTime.Date).ToOADate)
                      .AddWithValue("'@IsAdmin", ChkIsAdmin.Checked())
                                            
                    End With

                    SqlAppendCmd.ExecuteNonQuery()


Was This Post Helpful? 0
  • +
  • -

#15 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 293
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: Syntax error in INSERT INTO statement.

Posted 11 November 2010 - 07:32 AM

Right, so the person who posted first, TinaG using VB.Net, changed to Guest_Yuri Gagari* using C#, then after a few months changed to kojima100 using VB.Net again and ALL of them with totally different querries and different tables, hell they could even be different databases...oops I saw it, it moved from OLEDB to SQL... what is going on here?

OK THIS IS AN INSERT COMMAND:

INSERT INTO Table (field, field, field) VALUES ('value', 'value', 'value')



Just as charliemay said. Look at the brackets "(" and ")" where they are positioned... also if you named your field like "User Name" (a space in between) then you have to use these brackets "[" and "]".

so it would look like this

INSERT INTO Table ([field], [field], [field]) VALUES ('value', 'value', 'value')


This post has been edited by motcom: 11 November 2010 - 07:33 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1