VB.NET と SQL SERVER 2005 プラットフォームを使用して最終試験プロジェクトに取り組んでいます。データベース内に特定の日付または時刻がある場合は、特定の日付または時刻を選択するときに競合を検出する必要があります。
私はすでにSQLサーバーにSQLクエリを持っており、うまく機能しています。しかし、vb.net プロジェクトで実行しようとすると、問題が発生し始めます。私はこれで苦労しています。どんな助けでも大歓迎です。
マイテーブル
Item DateFrom DateTo TimeFrom TimeTo
Diamond 3/10/2013 3/20/2013 NULL NULL
Cooler 3/10/2013 3/20/2013 NULL NULL
Cooler 3/21/2013 NULL 9:30:00 AM 11:00:00 AM
Diamond 3/21/2013 NULL 8:00:00 AM 9:30:00 AM
mySQL
select count(*) from myTable
where '3/21/2013' between(datefrom)and(dateto) and item = 'Diamond'
or datefrom = '3/21/2013' and timefrom between '8:00 AM' and '10:00 AM' and item = 'Diamond'
or datefrom = '3/21/2013' and timeto between '8:00 AM' and '10:00 AM' and item = 'Diamond'
or datefrom = '3/21/2013' and '8:00 AM' between(timefrom)and(timeto) and item = 'Diamond'
結果: 1
ここに私のvb.netコードがあります
SQLQUERY = "Select Count(*) as Conflicts from myTable" & _
"Where '" & dtpTFrom.Value & "' between(datefrom)and(dateto) and item = '" & cmbItems.Text & "'" & _
"Or (datefrom = '" & dtpTFrom.Value & "' and timefrom between '" & Format(CDate(cmTFrom.Text), "hh:mm tt") & "' and '" & Format(CDate(cmTTo.Text), "hh:mm tt") & "' and item = '" & cmbItems.Text & "')" & _
"Or (datefrom = '" & dtpTFrom.Value & "' and timeto between '" & Format(CDate(cmTFrom.Text), "hh:mm tt") & "' and '" & Format(CDate(cmTTo.Text), "hh:mm tt") & "' and item = '" & cmbItems.Text & "')" & _
" Or (datefrom = '" & dtpTFrom.Value & "' and '" & Format(CDate(cmTFrom.Text), "hh:mm tt") & "' between(timefrom)and(timeto) and item ='" & cmbItems.Text & "')"
com = new sqlcommand(SQLQUERY,con)
dr = com.ExecuteReader()
dr.Read()
If dr.HasRows Then
MsgBox(CInt(dr.GetValue(0)))
If CInt(dr.GetValue(0)) > 0 Then
MessageBox.Show("Selected item is not available for that date and time.", AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
終了条件
メッセージ ボックスの結果: 0