Can Somebody help me? i have an error whenever i want to save the data i have retrieved from different table in mysql. my system is doorlock system. im going to choose an item in the combobox and when i click the button, the data i'd chose from the combo box will be retrieved and will be saved in different table. but if it's not in the database there will be a messagebox that is going to appear saying " Invalid Input." i tried this codes:
Imports MySql.Data.MySqlClient
Public Class Form2
Dim conn As MySqlConnection
Dim comm As MySqlCommand
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
conn = New MySqlConnection
conn.ConnectionString = "server=localhost;userid=root;password=;database=admin"
Dim Reader As MySqlDataReader
Try
conn.Open()
Dim Query As String
Query = "select * from admin.schedule where section= '" & ComboBox1.SelectedItem & "', name= '" & ComboBox2.SelectedItem & "', subject= '" & ComboBox3.SelectedItem & "', room= '" & Label6.Text & "', timein= '" & TextBox1.Text & "', timeout='" & TextBox2.Text & "'"
comm = New MySqlCommand(Query, conn)
Reader = comm.ExecuteReader
If Reader.HasRows Then
conn.Open()
Query = "insert into door1 (room_no,name,subject,section,time_login) values ('" & Label6.Text & "', '" & ComboBox1.SelectedItem & "','" & ComboBox2.SelectedItem & "','" & ComboBox3.SelectedItem & "', '" & Label1.Text & "')"
comm = New MySqlCommand(Query, conn)
Reader = comm.ExecuteReader
MessageBox.Show("Log in successful")
Else
MessageBox.Show("Access Denied")
ComboBox1.Text = ""
ComboBox2.Text = ""
ComboBox3.Text = ""
TextBox1.Text = Nothing
TextBox2.Text = Nothing
End If
conn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
but it displays an error " You have an error in your SQL Syntax; check the manual that corresponds to your MySQL server version for the right syntax to use ' name= 'Daniel', subject= 'mech201', room= 'MAC laboratory', timein= '',timeout= '' at line1"
by the way im using visual basic 2010 .can somebody help me for the right command im going to use. Thank you