Dim intNumRows As Integer
Dim connection As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
Dim sqlroom As String
Dim conn As New SqlConnection(connection)
conn.Open()
sqlroom = "SELECT COUNT(*) FROM RESV WHERE ROOM_ID = '" & DropDownList1.SelectedValue & "' AND Convert(DateTime, '" & Me.CalendarPopup1.SelectedDate & "', 103) BETWEEN DATE_FROM AND DATE_TO AND Convert(DateTime, '" & Me.CalendarPopup2.SelectedDate & "', 103) BETWEEN DATE_FROM AND DATE_TO "
Dim ccommand As New SqlCommand(sqlroom, conn)
intNumRows = ccommand.ExecuteScalar()
If intNumRows > 0 Then
Label1.Text = "NO"
Else
sqlroom = "SELECT COUNT(*) FROM RESV WHERE ROOM_ID = '" & DropDownList1.SelectedValue & "' AND DATE_FROM BETWEEN Convert(DateTime, '" & CalendarPopup1.SelectedDate & "', 103) AND Convert(DateTime, '" & CalendarPopup2.SelectedDate & "', 103) AND DATE_TO BETWEEN Convert(DateTime, '" & CalendarPopup1.SelectedDate & "', 103) AND Convert(DateTime, '" & CalendarPopup2.SelectedDate & "', 103) "
Dim bcommand As New SqlCommand(sqlroom, conn)
Dim intNumRows2 As Integer
intNumRows2 = bcommand.ExecuteScalar()
If intNumRows2 > 0 Then
Label2.Text = "NO"
Else
Dim com As New SqlCommand(sqlroom, conn)
Dim dr As SqlDataReader = com.ExecuteReader
GridView1.DataSource = dr
GridView1.DataBind()
dr.Close()
conn.Close()
End If
End If
End Sub