Hi Guyz,
i just wanna know how to fix my problem, or rather fix my code and simply my code base on my MODULE.

heres the error
" You have an error in your SQL syntax; check the manual that corresponds to your
mysql server version for the right syntax use near "at line 1"

thats the error appear when im tring to save the record.

this is my code in that form.

Imports MySql.Data.MySqlClient
Public Class Form10


    Private Sub Form10_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        frUpdate = False
    End Sub



    Private Sub Form10_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim con As New MySqlConnection
        Dim constr As String = "server=localhost; user id=root; password=phoenix0931; database=accounts;"


            con.ConnectionString = constr


        Catch ex As MySqlException


        End Try

        'For Customer Filter 
            Dim sStmt As String = "SELECT customers_id, customer_name, customer_add FROM customers"

            Dim cmd As New MySqlCommand(sStmt, con)

            Dim da As MySqlDataAdapter = New MySqlDataAdapter(cmd)

            Dim dt As New DataTable("customers")


            If dt.Rows.Count > 0 Then

                ComboBox1.DataSource = dt

                ComboBox1.DisplayMember = "customer_name"
                ComboBox1.ValueMember = "customers_id"
                TextBox2.DataBindings.Add("Text", dt, "customer_add")

            End If

        Catch ex As MySqlException


        End Try

            Dim sStmt1 As String = "SELECT product_id, product_name, product_description, maker, brand, price FROM products"

            Dim cmd1 As New MySqlCommand(sStmt1, con)

            Dim da1 As MySqlDataAdapter = New MySqlDataAdapter(cmd1)

            Dim dt1 As New DataTable("products")


            If dt1.Rows.Count > 0 Then

                ComboBox2.DataSource = dt1

                ComboBox2.DisplayMember = "product_name" 'What is displayed
                ComboBox2.ValueMember = "product_id"
                TextBox5.DataBindings.Add("Text", dt1, "product_description")
                TextBox6.DataBindings.Add("Text", dt1, "maker")
                TextBox7.DataBindings.Add("Text", dt1, "brand")
                TextBox8.DataBindings.Add("Text", dt1, "price")
            End If

        Catch ex As MySqlException


        End Try
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If frUpdate = False Then

            IsConnected("Insert into user values(" & _
                        Me.DateTimePicker1.Text & ",'" & _
                        Me.ComboBox1.Text & ",'" & _
                        Me.TextBox2.Text & "','" & _
                        Me.ComboBox2.Text & ",'" & _
                        Me.TextBox5.Text & "','" & _
                        Me.TextBox6.Text & "','" & _
                        Me.TextBox7.Text & ",'" & _
                        Me.TextBox8.Text & ",'" & _
                        Me.TextBox9.Text & ",'" & _
                        Me.TextBox10.Text & ",'" & _
                        Me.TextBox3.Text & "')", True)
            MsgBox("Successfully saved!", MsgBoxStyle.Information, "Information")

        End If

    End Sub

    Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
    End Sub

End Class

Heres my Code on my MODULE

Imports MySql.Data.MySqlClient
Module Module1
    Public myConn As New MySqlConnection
    Public myCmd As New MySqlCommand
    Public myDR As MySqlDataReader
    Public frUpdate As Boolean

    Public Function IsConnected(ByVal strQry As String, ByVal ver As Boolean)

            If myConn.State = ConnectionState.Open Then myConn.Close()
            myConn.ConnectionString = "server=localhost; user id=root; password=phoenix0931; database=accounts;"

            myCmd.CommandText = strQry
            myCmd.Connection = myConn

            If ver = False Then
                myDR = myCmd.ExecuteReader() 'For reading query

                myCmd.ExecuteNonQuery() 'For updating query

            End If

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
        End Try

    End Function

End Module

Anyone? can fix my error and simplify my code based on my module..

Need some help :( thnx

7 Years
Discussion Span
Last Post by bestex

Your first field to insert cames from a date picker, so I guess it is a date. If a date field is defined un the user table, you should put a value, between apostrophes like a text, and in the format of yyyy-MM-dd to be clearly understood by MySql like

"Insert into user values('" & _
      Format(Ctype(Me.DateTimePicker1.Text,DateTime),"yyy-MM-dd") & "','" & _
      Me.ComboBox1.Text & ",'" & _

Hope this helps

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.