Search button

Posted on 2011-05-12
Last Modified: 2012-05-11

I'm working in Hotel booking web site, and doing search for the available rooms.
My question is:

Which is the best way to create search function?
And should to use Like or Full text in SQl.
Plz if you provide me with example because I'm very beginner in ASP.NET C#
Question by:Alomiry
    LVL 3

    Expert Comment

    select * from rooms where vacant = true.  something along those lines. check syntax, obviously.


    Author Comment

    then should i use LIKE Operator.

    Can you provide me an example?

    LVL 8

    Expert Comment

    by:Anurag Agarwal
    Alomiry it depends upon the type of db structure u have, if possible give ur table structure of hotel boking so as to explain clearly.

    select * from rooms where vacant = 0 (where 0-vacant and 1-occupied )
    another for like statement is used for matching patterns in columns of records for helping urself for like statement go through SQL Like


    Accepted Solution

    I have the main TABLE from HOTELS and child TABLE for the ROOM_TYPE and the relation between the HOTELS AND ROOM TYPE 1-Many.

    I Just to know the best way to create the search for the hotels room, and can i use Full Text search because i read about it and it's better then LIKE .


    This is some of my code behinde:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Text;
    using System.Data.Sql;
    using System.Data.SqlClient;
    using System.IO;

    namespace BookingWebApplication

        public partial class Addyourhotel : System.Web.UI.Page

            string AddType;
            string AddRates;
            string AddHotelName;
            string AddCity;
            string AddStreet;
            string AddZipCode;
            string AddCountry;
            string AddBuildingNo;

            string AddContactName;
            string AddPhone;
            string AddFax;
            string AddWebsite;
            string AddEmail;

            string AddHotelDescription;
            string AddCheckIn;
            string AddCheckOut;

            string AddDistanceCenter;
            string AddDistanceTrain;
            string AddDistanceBeach;

            string AddFacilities;
            string AddService;

            string AddRoomName;
            string AddRoomName2;
            string AddRoomName3;
            string AddRoomDescription;
            string AddRoomDescription2;
            string AddRoomDescription3;

           /// int AddPersonPerRoom;
           ///int AddPersonPrice;

            string AddTerms;
            string AddPolicy;

            protected void Page_Load(object sender, EventArgs e)

            protected void Addyourhotel_Click(object sender, EventArgs e)
                AddType = id_type.SelectedItem.Value;
                AddRates = id_rate.SelectedItem.Value;
                AddHotelName = id_HotelName.Text;
                AddCity = id_city.Text;
                AddStreet = id_street.Text;
                AddZipCode = id_zipCode.Text;
                AddCountry = id_country_select.SelectedItem.Value;
                AddBuildingNo = id_buildingNo.Text;

                AddContactName = id_name.Text;
                AddPhone = id_phone.Text;
                AddFax = id_fax.Text;
                AddWebsite = id_web.Text;
                AddEmail = id_email.Text;

                AddHotelDescription = id_hotelDescription.Text;
                AddCheckIn = id_checkIn.Text;
                AddCheckOut = id_checkOut.Text;

                AddDistanceCenter = id_distance_center.Text;
                AddDistanceTrain = id_distance_train.Text;
                AddDistanceBeach = id_distance_beach.Text;

                AddFacilities = id_facilities.Text;
                AddService = id_service.Text;

                AddRoomName = id_room_name.Text;

                AddRoomName2 = id_room_name2.Text;

                AddRoomName3 = id_room_name3.Text;

                AddRoomDescription = id_room_description.Text;

                AddRoomDescription2 = id_room_description2.Text;

                AddRoomDescription3 = id_room_description3.Text;

                ///AddPersonPerRoom = Convert.ToInt32(id_room_person.Text);
                ///AddPersonPrice = Convert.ToInt32(id_room_price.Text);

                AddTerms = id_terms.Text;
                AddPolicy = id_policy.Text;

                SqlConnection cnn = new SqlConnection();
                cnn.ConnectionString =
                @"Data Source=localhost\SQLEXPRESS;
                       AttachDbFilename=C:\Users\Anas\Documents\Visual Studio 2010\Projects\BookingWebApplication\BookingWebApplication\App_Data\Booking.mdf;
                       Integrated Security=True;
                       User Instance=True";


                Label1.Text = "<b>Server Version:</b> " + cnn.ServerVersion;

                SqlCommand query = cnn.CreateCommand();

                query.CommandText = "INSERT INTO [Hotel] ([Type],[Rates],[Name],[City],[Street],[ZipCode],[Country],[BulidingNumber],[ContactFullName],[PhoneNumber],[FaxNumber],[Website],[Email],[Hotel_description],[Check_in],[Check_out],[Distance_center],[Distance_train],[Distance_beach],[FacilitiesDescription],[ServiceDescription],[Terms_condition],[Policy]) VALUES ('" + AddType + "','" + AddRates + "','" + AddHotelName + "','" + AddCity + "','" + AddStreet + "','" + AddZipCode + "','" + AddCountry + "','" + AddBuildingNo + "','" + AddContactName + "','" + AddPhone + "','" + AddFax + "','" + AddWebsite + "','" + AddEmail + "','" + AddHotelDescription + "','" + AddCheckIn + "','" + AddCheckOut + "','" + AddDistanceCenter + "','" + AddDistanceTrain + "','" + AddDistanceBeach + "','" + AddFacilities + "','" + AddService + "','" + AddTerms + "','" + AddPolicy + "'); SELECT SCOPE_IDENTITY();";

                decimal hotelid = (decimal)query.ExecuteScalar();

                query.CommandText = "INSERT INTO [Room_type] ([Hotels_id],[Name],[Description]) VALUES ('" + hotelid.ToString() + "','" + AddRoomName + "','" + AddRoomDescription + "');";

                query.CommandText += "INSERT INTO [Room_type] ([Hotels_id],[Name],[Description]) VALUES ('" + hotelid.ToString() + "','" + AddRoomName2 + "','" + AddRoomDescription2 + "')";

                query.CommandText += "INSERT INTO [Room_type] ([Hotels_id],[Name],[Description]) VALUES ('" + hotelid.ToString() + "','" + AddRoomName3 + "','" + AddRoomDescription3 + "')";

                 if (Page.IsValid) //save the image
                   Stream imgStream = UploadFile.PostedFile.InputStream;
                   int imgLen = UploadFile.PostedFile.ContentLength;
                   string img_contenttype = UploadFile.PostedFile.ContentType;
                   string img_name = txtImgName.Value;
                   byte[] img_data = new byte[imgLen];
                   int n = imgStream.Read(img_data, 0, imgLen);
                   String idis = Request.QueryString["id"];
                   int business_id = System.Convert.ToInt32(idis);
                   int RowsAffected = SaveToDB(img_name, img_data, img_contenttype);
                   if (RowsAffected > 0)
                       TextBox TextBox2 = new TextBox();
                       TextBox2.Text = "The Image was Saved";
                       Response.Write("<BR>The Image was saved");
                       Response.Write("<BR>An error occurred uploading the image");

           private int SaveToDB(string img_name, byte[] img_data, string img_contenttype)
               //use the web.config to store the connection string

               SqlConnection cnn = new SqlConnection();
               cnn.ConnectionString =
               @"Data Source=localhost\SQLEXPRESS;
                      AttachDbFilename=C:Documents\Visual Studio 2010\Projects\BookingWebApplication\BookingWebApplication\App_Data\Booking.mdf;
                      Integrated Security=True;
                      User Instance=True";



               SqlCommand query = cnn.CreateCommand();

                query.CommandText = "INSERT INTO Hotels (Image_name,Image_data, Image_contenttype) VALUES ( @img_name, @img_data,@img_contenttype)";
               SqlParameter param0 = new SqlParameter("@img_name", System.Data.SqlDbType.VarChar, 50);
               param0.Value = img_name;
              SqlParameter param1 = new SqlParameter("@img_data", System.Data.SqlDbType.Image,img_data.Length);
               param1.Value = img_data;

               SqlParameter param2 = new SqlParameter("@img_contenttype", System.Data.SqlDbType.VarChar, 50);
               param2.Value = img_contenttype;
               int numRowsAffected = query.ExecuteNonQuery();
               return numRowsAffected;


    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now