gpt4 book ai didi

mysql - 从字符串到 double 的转换无效

转载 作者:行者123 更新时间:2023-11-29 12:15:08 24 4
gpt4 key购买 nike

导入MySql.Data.MySqlClient

公开课预订表

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 类型的转换无效”正如你所看到的,我没有尝试将任何内容转换为 double

请帮忙

最佳答案

这将隐式尝试转换为 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
....

比较长度不会在比较之前尝试将其转换为 double 型。

关于mysql - 从字符串到 double 的转换无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29942650/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com