varcharであるデータベースの列からデータを読み込み、読み込み結果をstringに格納するようにします。変数ですが、indexoutofrange例外を生成します...基本的には、ユーザーがデータベースに既にある予約時間を入力すると、プログラムはエラーメッセージを生成するように、検証を行います。また、入力された値が予約された時間内にある場合は、エラーが生成されます。もし予約が12/12/2011午後4時にあり、期間が2時間の場合、予約は他のゲームや他の法廷の予約でない限り、プログラムは午後6時までに予約を許可しないでください選択クエリ私はdatareaderがvarcharであるデータベースの列からデータを読み込み、読み込み結果を文字列変数に格納するようにします
str2 = "select booking_date, booking_time, booking_duration, poolno, courtno, tableno from Bookings"
Dim a, b As Date
Dim c As Date
Dim d, f, g, l As String
Dim dur As Integer
Dim cmd2 As New SqlCommand(str2, con)
con.Open()
Dim bookchk As SqlDataReader = cmd2.ExecuteReader
While bookchk.Read()
a = bookchk("booking_date")
b = bookchk("booking_time")
c = b.ToLongTimeString
dur = bookchk("booking_duration")
l = bookchk("game") 'exception is generated here
If CmboGame.SelectedItem = "Swimming" Then
If bookchk("poolno") IsNot System.DBNull.Value Then
d = bookchk("poolno")
End If
Else : d = ""
End If
If CmboGame.SelectedItem = "Table Tennis" Then
If bookchk("tableno") IsNot System.DBNull.Value Then
f = bookchk("tableno")
End If
Else : f = ""
End If
If CmboGame.SelectedItem IsNot "Table Tennis" And CmboGame.SelectedItem IsNot "Swimming" Then
If bookchk("courtno") IsNot System.DBNull.Value Then
g = bookchk("courtno")
End If
Else : g = ""
End If
If TxtBookDate.Text = a And TxtBookTime.Text = c And TxtPoolNo.Text = d And TxtCrtNo.Text = g And TxtTblNo.Text = f And CmboGame.SelectedItem = l Then
MessageBox.Show("The date and time you have entered has already been booked" & vbCrLf & "Try Again!", "Bookings Overlapped", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Exit Sub
End If
Dim time, h, i, j, n As DateTime
n = c.AddHours(dur)
time = TxtBookTime.Text
h = time.AddHours(TxtBookDur.Text)
i = time.ToLongTimeString
j = h.ToLongTimeString
If TxtBookDate.Text = a And TxtPoolNo.Text = d And TxtCrtNo.Text = g And TxtTblNo.Text = f And CmboGame.SelectedIndex = l And i > c And i <= n Or j > n Then
MessageBox.Show("The date and time you have entered has already been booked" & vbCrLf & "Try Again!", "Bookings Overlapped", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Exit Sub
End If
End While
bookchk.Close()
con.Close()
ありがとう...コード内で変更を加えたので、クエリを変更するのを忘れてしまいました。ありがとうございます:-) –
重複した予約を避けるために、私はいくつかの異なるcourtno/poolno/tblnoを予約しようとした場合、または同じゲーム内で試してみると、エラーメッセージが表示されます。 –
同じ質問の中で複数の質問をするのは良い考えです。その問題の詳細は何も示されていないので、誰でもアドバイスを提供することは非常に難しいです。 – SpaceBison