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
Me.Dispose()
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;"
Try
con.ConnectionString = constr
con.Open()
Catch ex As MySqlException
MsgBox(ex.Message)
End Try
'For Customer Filter
Try
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")
da.Fill(dt)
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
MsgBox(ex.Message)
End Try
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")
da1.Fill(dt1)
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
MsgBox(ex.Message)
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
Me.Dispose()
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)
Try
If myConn.State = ConnectionState.Open Then myConn.Close()
myConn.ConnectionString = "server=localhost; user id=root; password=phoenix0931; database=accounts;"
myConn.Open()
myCmd.CommandText = strQry
myCmd.Connection = myConn
If ver = False Then
myDR = myCmd.ExecuteReader() 'For reading query
Else
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