【发布时间】:2017-06-12 16:35:54
【问题描述】:
程序能够运行。但是当点击功能按钮时,错误说数据读取器没有关闭,我实际上是这样做的。1
有什么解决办法吗?
错误:已经有一个打开的 DataReader 与此命令关联,必须先关闭。
Else
If checkoutdate.Value >= checkindate.Value Then
cmdsearch.CommandText = "SELECT * FROM [Reservations] where [ReservationID] = " & reservationidlbl.Text
cmdupdate.CommandType = CommandType.Text
cmdsearch.Connection = cnnoledb
Dim read3 As OleDbDataReader = cmdsearch.ExecuteReader()
If checkindate.Value & checkoutdate.Value >= read3(5) & read3(6) Then
If read3(5) & read3(6) <= checkindate.Value & checkoutdate.Value Then
cmdupdate.CommandText = "INSERT INTO [Reservations] (ReservationID, [RoomNo], CustomerName, [IC/Passport], ContactNo, [CheckIn_Date], [CheckOut_Date], RoomType, Deposit, ReservationDate,[Status]) values ( '" & reservationidlbl.Text & "' , '" & roomtxt.Text & "', '" & nametxt.Text & "', '" & passporttxt.Text & "', '" & contacttxt.Text & "','" & checkindate.Text & "','" & checkoutdate.Text & "','" & roomtype2 & "','" & deposittxt.Text & "','" & DateAndTime.Now.ToString & "', '" & status & "')"
cmdupdate.CommandType = CommandType.Text
cmdupdate.Connection = cnnoledb
cmdupdate.ExecuteNonQuery()
MsgBox("Reservation made.")
Else
MsgBox("This room is reserved for the specified date.")
End If
read3.Close()
Else
MsgBox("This room is reserved for the specified date.")
End If
read3.Close()
【问题讨论】:
-
如果您不发布有问题的代码,要弄清楚您做错了什么有点困难。
-
在
End If之后插入这个:If read3.IsClosed = False Then read3.Close() -
请添加您收到的准确错误消息。
-
@muffi 我做了,但还是一样。
-
@ChrisDunaway 完成。
标签: database vb.net ms-access reader