|
-
Jun 27th, 2011, 11:38 AM
#1
Thread Starter
Member
Implementing a search function
Hey guys, im trying to implement a search function to my booking program, wich retrieves data from a SQL database. I have the screan all set up and all the variables at the ready, the only problem is, im not sure how to execute it in a sqlcommand line.
I've got all the fields that are required, such as date, time but i also have two optional options, Room Type and Room Capacity.
How would i write a sqlcommand to search for available rooms that meet the criteria for the room to be booked?
Heres the code i have so far;
Code:
'Declare Variables
Dim sRoomType As String = CStr(cbRoomType.SelectedItem)
Dim iRoomCap As Integer = CInt(cbRoomCap.SelectedItem)
Dim dStartDate As Date = McDateRequired.SelectionRange.Start
Dim arr1 = cbStartTime.Text.Split(":"c)
Dim arr2 = cbEndTime.Text.Split(":"c)
Dim dStartTime As Date = New Date(1900, 1, 1, CInt(arr1(0)), CInt(arr1(1)), 0)
Dim dEndTime As Date = New Date(1900, 1, 1, CInt(arr2(0)), CInt(arr2(1)), 0)
'If repeat booking is needed then declare variable to hold end date
If McEndDate.Visible = True Then
Dim dEndDate = McEndDate.SelectionRange.End
End If
'Set current date
Dim CurrentDate As DateTime = DateTime.Now
'Check that all data is selected, except optionals
'Check that selected date is not earlier than current date
If dStartDate < CurrentDate Or dEndTime < dStartDate Then
MessageBox.Show("Error! Date selected is invalid", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
'Check start & end time
If cbStartTime.SelectedText = "" Or cbEndTime.SelectedText = "" Then
MessageBox.Show("Error! Please select a valid Start & End time!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
'Search Database for rooms matching criteria
'Open connection
connection.Open()
Dim SearchRooms As New SqlCommand("SELECT Location WHERE
(And obviously this is where im stuck
any help would be greatley appreciated!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|