進口MySql.Data.MySqlClient轉換無效
公共類BookingForm
Dim MySqlConn As MySqlConnection
Dim Command As MySqlCommand
Dim Valid As Boolean = False
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Call Input_Validation()
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString = "Server = Localhost; database = venuesdb; user id = root; Password = "
Dim Reader As MySqlDataReader
Try
MySqlConn.Open()
Dim Query As String
Query = "Insert into venuesdb.Event(VenueID, EventName, EventDate, EventStartTime, EventEndTime, EventID, CustomerID) Values ('" & TextBox1.Text & "', '" & TextBox2.Text & "', '" & DateTimePicker1.Text & "', '" & TextBox4.Text & "', '" & TextBox5.Text & "', '" & TextBox6.Text & "', '" & TextBox7.Text & "')"
Command = New MySqlCommand(Query, MySqlConn)
Reader = Command.ExecuteReader
MessageBox.Show("Booking Added")
MySqlConn.Close()
If TextBox1.Text = 0 Then
MessageBox.Show("Please enter text")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
TextBox1.Clear()
TextBox2.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString = "Server = Localhost; database = venuesdb; user id = root; Password = "
Dim Reader As MySqlDataReader
Try
MySqlConn.Open()
Dim Query As String
Query = "Delete from venuesdb.Event where EventName = '" & ComboBox1.Text & "'"
Command = New MySqlCommand(Query, MySqlConn)
Reader = Command.ExecuteReader
MessageBox.Show("Booking Deleted")
MySqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
End Sub
Private Sub TabPage2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString = "Server = Localhost; database = venuesdb; user id = root; Password = "
Dim Reader As MySqlDataReader
Try
MySqlConn.Open()
Dim Query As String
Query = "Select * from venuesdb.Event"
Command = New MySqlCommand(Query, MySqlConn)
Reader = Command.ExecuteReader
While Reader.Read
Dim Bandname = Reader.GetString("EventName")
ComboBox1.Items.Add(Bandname)
End While
MySqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
End Sub
Private Sub BookingForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub TabPage3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString = "Server = Localhost; database = venuesdb; user id = root; Password = "
Dim Reader As MySqlDataReader
Try
MySqlConn.Open()
Dim Query As String
Query = "Select * from venuesdb.Event"
Command = New MySqlCommand(Query, MySqlConn)
Reader = Command.ExecuteReader
While Reader.Read
Dim Bandname = Reader.GetString("EventName")
ComboBox2.Items.Add(Bandname)
End While
MySqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString = "Server = Localhost; database = venuesdb; user id = root; Password = "
Dim Reader As MySqlDataReader
Try
MySqlConn.Open()
Dim Query As String
Query = "Select * from venuesdb.Event Where EventName = '" & ComboBox2.Text & "'"
Command = New MySqlCommand(Query, MySqlConn)
Reader = Command.ExecuteReader
While Reader.Read
TextBox14.Text = Reader.GetString("EventName")
TextBox13.Text = Reader.GetString("VenueID")
TextBox11.Text = Reader.GetString("EventStartTime")
TextBox10.Text = Reader.GetString("EventEndTime")
TextBox9.Text = Reader.GetString("EventID")
TextBox8.Text = Reader.GetString("CustomerID")
DateTimePicker2.Text = Reader.GetDateTime("EventDate")
End While
MySqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString = "Server = Localhost; database = venuesdb; user id = root; Password = "
Dim Reader As MySqlDataReader
Try
MySqlConn.Open()
Dim Query As String
Query = "Update venuesdb.Event set EventName = '" & TextBox1.Text & "', VenueID = '" & TextBox2.Text & "', EventDate = '" & DateTimePicker2.Text & "'where EventName = '" & TextBox1.Text & "'"
Command = New MySqlCommand(Query, MySqlConn)
Reader = Command.ExecuteReader
MessageBox.Show("Booking Updated")
MySqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
TextBox1.Clear()
TextBox2.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
End Sub
我有不斷彈出,當我點擊一個按鈕,一個錯誤的錯誤說「轉換,從字符串「」到類型雙無效」 正如你可以看到我沒試過的東西轉換翻一番
請幫助
你確定這是拋出異常的地方嗎?沒有其他班級轉換爲「Double」? –
不,我已經檢查過所有表格,我還沒有轉換任何東西到雙? –
開關選項嚴格的開始以... –