导入MySql.Data.MySqlClient
Public Class 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类型无效” 如您所见,我没有尝试将任何内容转换为双重
请帮助
答案 0 :(得分:1)
这将隐式尝试转换为Double以尝试运行比较:
If TextBox1.Text = 0 Then
MessageBox.Show("Please enter text")
End If
您可能希望将其(以及任何其他事件)包装在
中If Textbox1.Text <> "" Then
If TextBox1.Text = 0 Then
MessageBox.Show("Please enter text")
End If
End If
或者,或许甚至更好,将其改为:
If TextBox1.Text.Length = 0 Then
....
或
If TextBox1.Text = "" Then
....
比较长度不会尝试在比较之前将其转换为双倍。