Click here to Skip to main content
15,849,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi is there any code to find appointment availability.
i want to compare two dates that come from database and two other date that user input from textbox.
User insert two date, start_date and end_date from asp.net textbox if between those 2 data any data were find in database it show message "slot allready book" else "booking successful".
Help me
thanks in advance

this is my table definition

<img src="http://s12.postimg.org/5gb83qfnx/database_design.png"></img>

I have inserted some data
<img src="http://s10.postimg.org/423vmgjqh/tabledata.png"></img>

And this is my asp.net page design
<img src="http://s11.postimg.org/opkagl54z/form.png"></img>

i use this code but not work properly
C#
protected void Button1_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection(str);
    con.Open();
    SqlCommand cmd_read = new SqlCommand("select start__date,end__date from meeting", con);
    SqlDataReader dr = cmd_read.ExecuteReader();
    while (dr.Read())
    {
        start =Convert.ToDateTime( dr[0].ToString());
        end = Convert.ToDateTime(dr[1].ToString());

        DateTime str1 = DateTime.Parse(TextBox2.Text);
        DateTime str2 = DateTime.Parse(TextBox3.Text);
        if((str1 > start && str1 < end) || (str2 > start && str2 < end))
        {
    Label5.Text = "Already Booked";
    break;
        }
        else{
            Label5.Text = "Available";
            break;
        }
    }

    con.Close();
}

Help me soon...
Posted
Updated 22-May-13 20:11pm
v2

1 solution

you can solve it by stored procedure.


SQL
CREATE PROCEDURE CHECKMEETINGDATE
(
    @TXTDATE1   NVARCHAR(10)
    , @TXTDATE2 NVARCHAR(10)
)
AS
BEGIN
    SET NOCOUNT ON
        IF(SELECT TOP 1 1 FROM Meeting WHERE @TXTDATE1 BETWEEN start_date AND end_date)
        BEGIN
            SELECT 'Already Booked'
        END
        ELSE IF (SELECT TOP 1 1 FROM Meeting WHERE @TXTDATE2 BETWEEN start_date AND end_date)
        BEGIN
        END
            SELECT 'Already Booked'
        ELSE
        BEGIN
            SELECT 'Available'
        END
    SET NOCOUNT OFF
END
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900