i have a form whcih is room and in this there is when i add a data on it that is

room id,room no and service type and room type

then when i add the data like as
room id=1
room no=2
room type=double
service type=luxury

then when i again add the data with ths same room number whcih is already booked then how to show it that this room no is already booked ...

here is room add fuction coding

 public void add()
        {

            string ConString = @"Data Source=USER-PC\SQLEXPRESS;Initial Catalog=htm;Integrated Security=True";
            SqlConnection con = new SqlConnection(ConString);

            con.Open();
            DataTable dt = new DataTable();

            SqlCommand com = new SqlCommand("insertroominfo", con);


            com.CommandType = CommandType.StoredProcedure;
            //com.Parameters.Add(new SqlParameter("@guest_ID", guest_id));
            com.Parameters.Add(new SqlParameter("@room_no",roominfo.Room_no));
            com.Parameters.Add(new SqlParameter("@service_id", roominfo.Service_type));
            com.Parameters.Add(new SqlParameter("@RoomTypeID", roominfo.Room_type));
            com.ExecuteNonQuery();
            con.Close();
        }

and here is add button coding

        private void Add_Click(object sender, EventArgs e)
        {


            Room_manager manageroom = new Room_manager(room);


                room.Service_type=Convert.ToString(service_type.SelectedValue);
               room.Room_type = Convert.ToString(room_type.SelectedValue);
                room.Room_no = Convert.ToInt32(room_no.Text);
                manageroom.add();
                //dataGridView1.DataSource = room.displaydata();
                MessageBox.Show("Room Added Successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dt.Clear();
                dt = room.displaydata();

                dataGridView1.DataSource = dt;
                clearfield1();

        }

anybody help plz

Since you clear the table in line 14 there are no other rooms that are booked. Otherwise you'll have to search the table and see if the room is booked, or set a unique constraint on the column (not sure if you can do that with DataTables, I don't use them :))

no...line 14 i comment it this line is not use in this....

and how i done this :/

you could set a unique enum field or int field as a default of 0, if the room is in use set as 1 that way if any new data is entered and if room_inuse is equal to 1 then messagebox.show("Im Sorry" + "\r\n" + "Room: " + roomID + " is in use","Warning!");

are you showing room information inside a datagrid view?
you could display active room cycle inside a datagrid view using a foreach loop

hmm

in room i only show
room id,room no ,service type and room type

and how i use this
can u plz write in code

Use the room ID if it equals 999, or any number that will never get assigned, the room is open otherwise it's booked

still not understand concept =(

in room i only show
room id,room no ,service type and room type

I assume since you're showing room id that you are assigning some sort of value to it. Decide on a default value that you can use to signify not booked then when it is booked change the value to the one that was required in the first place.

private void Add_Click(object sender, EventArgs e)
{

    dt = room.displaydata(); //Get the datatable from the Database

    //Filter the datatable to check whether the room is already booked
    //An existence in the data table means the specific room is booked
    //I assume the field name is room_no
    DataRow[] filteredRows = dt.Select("room_no=" + Convert.ToInt32(room_no).Text);

    if (filteredRows.Count > 0) //Room is already booked
    {
        //Room is booked
        //Prompt user about the booking status
        MessageBox.Show("Room is already booked. Select another room no.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        return; //exit the function
    }

    Room_manager manageroom = new Room_manager(room);
    room.Service_type=Convert.ToString(service_type.SelectedValue);
    room.Room_type = Convert.ToString(room_type.SelectedValue);
    room.Room_no = Convert.ToInt32(room_no.Text);
    manageroom.add();
    //dataGridView1.DataSource = room.displaydata();
    MessageBox.Show("Room Added Successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
    dt.Clear();
    dt = room.displaydata();
    dataGridView1.DataSource = dt;
    clearfield1();
 }

i tried the error on it

Operator '>' cannot be applied to operands of type 'method group' and 'int'


in line 11
if (filteredRows.Count() > 0)

it seems like this
and thanuuu for solving

yup!!!! I forgot that ................... I didn't compile and check the code

if (filteredRows.Count() > 0)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.