Rocky Rocky

Rocky Rocky

  • NA
  • 317
  • 151.7k

error to validate inputdate is always greater than gridview

May 16 2013 3:47 AM
Hai friends,
  Im creating one application in i wanna to validate the input date if i choose same date where already in gridview date ll show alert message(already done).
 like the same wanna put validate for choosing input date is always greater than gridview date.how make code?


 protected void ADD_Click(object sender, EventArgs e)
    {


            bool readerHasRows = false;
            string depdate = Datepicker.Text;

            string commandQuery = "SELECT departuredate FROM onward_journey WHERE departuredate= @depdate";
            using (SqlCommand cmd = new SqlCommand(commandQuery, conn))
            {
                // conn.Open();
                cmd.Parameters.AddWithValue("@depdate", Datepicker.Text);
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    // bool initialized above is set here
                    readerHasRows = (reader != null && reader.HasRows); //&& reader >Datepicker);
                }
            }


            if (readerHasRows)
            {

                Response.Write("<script>alert('Departure Date Already Exists!!')</script>");
            }

            else
            {
                string sql;

                string de = Datepicker.Text;
                Session["de"] = de;
                if (de.length < Convert.ToInt16(depdate))/// ERROR :Input string was not in a correct format.
                {

                    Response.Write("<script>alert('Departure Date Always greater GridView's Date!!')</script>");
                }
                else
                {
                    sql = "insert into onward_journey(departuredate,from_location,to_location,metro,trans_all,mode_of_travel,seat_type,no_of_days,other_details,status_id) values(@departuredate,@from_location,@to_location,@metro,@trans_all,@mode_of_travel,@seat_type,@no_of_days,@other_details,'2')";
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    cmd.Parameters.AddWithValue("@departuredate", Datepicker.Text);
                    cmd.Parameters.AddWithValue("@from_location", TxtFm.Text);
                    cmd.Parameters.AddWithValue("@to_location", TxtTo.Text);
                    cmd.Parameters.AddWithValue("@metro", DDL_Metro.Text);
                    cmd.Parameters.AddWithValue("@trans_all", DDL_trans.Text);
                    cmd.Parameters.AddWithValue("@mode_of_travel", DDL_ModeOfTravel.Text);
                    cmd.Parameters.AddWithValue("@seat_type", DDL_SeatType.Text);
                    cmd.Parameters.AddWithValue("@no_of_days", TxtNo.Text);
                    cmd.Parameters.AddWithValue("@other_details", Txtothrdet.Text);
                    int count = cmd.ExecuteNonQuery();


                    //string st = "select  convert(varchar, departuredate, 103)as DepartureDate , from_location as 'From' ,to_location 'To', metro,trans_all as Trans,mode_of_travel as ModeOfTravel,seat_type as Seat, no_of_days as Numdays, other_details as OtherDetails from onward_journey";
                    //SqlDataAdapter de = new SqlDataAdapter(st, conn);
                    //DataTable dtStore = new DataTable();

                    //de.Fill(dtStore);

                    //grdvStore.DataSource = dtStore.DefaultView;

                    //grdvStore.DataBind();
                    DateTime val = new DateTime();
                    DateTime b = new DateTime();
                    val = Convert.ToDateTime(Datepicker.Text);

                    b = val.AddDays(Convert.ToInt32(TxtNo.Text));
                    binddata();
                    Datepicker.Text = b.ToString();
                    Datepicker.Enabled = false;
                    DDL_Metro.SelectedIndex = 0;
                    DDL_trans.SelectedIndex = 0;
                    DDL_ModeOfTravel.SelectedIndex = 0;
                    DDL_SeatType.SelectedIndex = 0;
                    TxtFm.Text = "";
                    TxtTo.Text = "";
                    TxtNo.Text = "";
                    Txtothrdet.Text = "";

                }