• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

Search button

Hello,

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#
0
Alomiry
Asked:
Alomiry
  • 3
1 Solution
 
redeinternaCommented:
select * from rooms where vacant = true.  something along those lines. check syntax, obviously.

0
 
AlomiryAuthor Commented:
then should i use LIKE Operator.

Can you provide me an example?

Regrads
0
 
Anurag AgarwalCommented:
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

0
 
AlomiryAuthor Commented:
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 .

Regards

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";

            cnn.Open();



            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");
                              }
               else
                             {
                   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";

           cnn.Open();
           

           

           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;
           query.Parameters.Add(param0);
 
          SqlParameter param1 = new SqlParameter("@img_data", System.Data.SqlDbType.Image,img_data.Length);
           param1.Value = img_data;
           query.Parameters.Add(param1);
 
                 

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





        }
   
}
   
0
 
AlomiryAuthor Commented:
Thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now