Results 1 to 4 of 4

Thread: Implementing a search function

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2010
    Posts
    63

    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!

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Implementing a search function

    This is all just basic SQL syntax that you'll be able to pickup easily by reading this.

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2010
    Posts
    63

    Re: Implementing a search function

    ah cheers i'm still pretty new with using SQL >_<

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Implementing a search function

    this is the basics of a select statement

    Select from sometableName where SomeField1 = somevalue1 and SomeField2 = somevalue2
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width