Here's the code:

Private Sub btdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btdAdd.Click

        'Sets up the connection to the database
        'Dim myConn As New OleDb.OleDbConnection()

        'Dim sql As String


        con.Open()
        Dim cmd As New OleDb.OleDbCommand ("INSERT INTO   Contacts(Company, First, Last, Title, Address, City, State," & _
               "ZipCode, OfficePhone, CellPhone, AssitantPhone, Fax,   [INDENT][/INDENT]Website, Country, Debt," & _
                [INDENT][/INDENT]"Equity, Mezzanine, Credit [INDENT][/INDENT]Enhancement)" & _
                       "VALUES('" & txtcompadd.Text & "', '" & txtFname.Text & "'," & _
                        "'" & txtLName.Text & "'," & _
                        "'" & txtTitleadd.Text & "', '" & txtaddressadd.Text & "'," & _
                        "'" & txtCityAdd.Text & "', '" & cbStateadd.Text & "'," & _
                        "'" & txtZipAdd.Text & "', '" & txtOffice.Text & "'," & _
                        "'" & txtCell.Text & "', '" & txtAssistant.Text & "'," & _
                       "'" & txtFaxAdd.Text & "', '" & txtWebAdd.Text & "'," & _
                       "'" & cbCountryAdd.Text & "', '" & cbdebt.CheckState & "'," & _
                       "'" & cbequity.CheckState & "', '" & cbmezzanine.CheckState & "'," & _
                        "'" & cbcredit.CheckState & "')"

I'm getting the error: Syntax error in INSERT INTO statement.

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

The SQL looks correct after removing all of the VB code. But there is no way to know what the functions cbdebt, cbequity, cbmezzanine, and cbcredit are returning. I would recommend saving the insert command text into a variable and posting that back to this thread. When you have that value, you might also try to run the insert command directly into what ever database you are using. I use MSSQL and find that taking my SQL statements directly into MSSQL and execute them there, I find many mistakes that would be very hard in VB, assuming that the error you posted is truly an error in the input statement.

Use parametrized query.

Dim cmd As New OleDb.OleDbCommand ()
 cmd.Connection=con
 cmd.CommandText="INSERT INTO   Contacts ([Company], [First], [Last], [Title], [Address], [City], [State],[ZipCode], [OfficePhone], [CellPhone], [AssitantPhone], [Fax],[Website], [Country], [Debt],[Equity], [Mezzanine], [CreditEnhancement]) VALUES(@Company, @First, @Last, @Title, @Address, @City, @State,@ZipCode, @OfficePhone, @CellPhone, @AssitantPhone, @Fax,@Website, @Country, @Debt,@Equity, @Mezzanine, @CreditEnhancement)"

 cmd.Parameters.AddWithValue("@Company",txtcompadd.Text)
 ....
 con.Open()
 cmd.ExecuteNonQuery();
 con.Close()
 ....
This article has been dead for over six months. Start a new discussion instead.