gpt4 book ai didi

mysql - Reader 关闭时读取无效 (VB.Net)

转载 作者:行者123 更新时间:2023-11-30 21:49:58 24 4
gpt4 key购买 nike

我目前在我的函数中遇到这个错误。情况是我需要向每个当前时间安排不佳的客户发送一条短信,因此我有一个 SQL 查询来选择具有正在进行的时间表的条目,并且对于 SQL 数据阅读器 (READER) 已读取的每个条目,它将执行我的短信代码。但是我收到了这个错误。

这是我的代码:

Public Function onschedule()
MysqlConn.ConnectionString = ServerString

Dim READER As MySqlDataReader
Dim mobileNum, customername, datestart, msg As String

Try
MysqlConn.Open()
Dim query As String

query = "SELECT DATE_FORMAT(ratedemand_datestart, '%M %d, %Y') as 'Date Start',ratedemand_contact as 'Contact Number',sales_customername as 'Customer Name' FROM bnb.ratedemand WHERE ratedemand_status = 'Reserved' AND NOW() = ratedemand_datestart AND rate_category='Billiard'"
COMMAND = New MySqlCommand(query, MysqlConn)
READER = COMMAND.ExecuteReader

While READER.Read
mobileNum = READER.GetString("Contact Number") '09856994598'
datestart = READER.GetString("Date Start") 'November 2, 2017 12:00 AM'
customername = READER.GetString("Customer Name") 'Bruce R. Wayne'

'SMS Code Starts Here'

If SerialPort.IsOpen Then
SerialPort.Close()
End If

msg = customername + ", this is an automated text from Sta. Lucia East Grand Mall Billiard Hall confirming your 'Billiard Schedule' on " + datestart + " (Right Now). We are reminding you that if you are 20 minutes behind your schedule. It will be automatically cancelled."

SerialPort.PortName = "COM4"
SerialPort.BaudRate = 9600
SerialPort.Parity = Parity.None
SerialPort.StopBits = StopBits.One
SerialPort.DataBits = 8
SerialPort.Handshake = Handshake.RequestToSend
SerialPort.DtrEnable = True
SerialPort.RtsEnable = True
SerialPort.NewLine = vbCrLf
SerialPort.Open()

If SerialPort.IsOpen() Then
SerialPort.Write("AT" & vbCrLf)
SerialPort.Write("AT+CMGF=1" & vbCrLf)
SerialPort.Write("AT+CMGS=" & Chr(34) & mobileNum & Chr(34) & vbCrLf)
SerialPort.Write("Message: " & msg & Chr(26))
Else
MetroMessageBox.Show(Admin_Menu, "Port not Available", "System Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End While

MysqlConn.Close()

Catch ex As Exception
MsgBox(ex.Message)
Finally
MysqlConn.Dispose()
End Try

Return True
End Function

最佳答案

不要低估关闭读者的必要性:)

Try
While Reader.Read()
...
End While
Finally
Reader.Close
MysqlConn.Close()
End Try

关于mysql - Reader 关闭时读取无效 (VB.Net),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47742855/

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