Name Mame

Name Mame

  • 1.6k
  • 160
  • 3.3k

How Retrieving data in grid view based on date from text box ?

Jul 14 2023 7:34 PM

Hello 

I need  to retrieve  data in grid view based on specific date in text box and by using stored procedure,

but the grid view not fill and nothing happened.

this is my code 

protected void btndate_Click(object sender, EventArgs e)
{

    if (Page.IsValid)
    {
        try
        {
            using (SqlConnection con = new SqlConnection(n))
            {
                using (SqlCommand command1 = new SqlCommand("RetrieveByDate", con))
                {
                    con.Open();

                     if (txtfrom.Text != string.Empty && txtfrom.Text != null && txtfrom.Text != "" && textto.Text != string.Empty && textto.Text != null && textto.Text != "")
                    {
                        command1.CommandType = CommandType.StoredProcedure;
                        command1.Parameters.AddWithValue("@Date1", txtfrom.Text);
                        command1.Parameters.AddWithValue("@Date2", textto.Text);
                        command1.ExecuteNonQuery();
                        SqlDataAdapter sda = new SqlDataAdapter(command1);
                        DataTable dt = new DataTable();
                        sda.Fill(dt);

                        dgQueries.DataSource = dt;                                
                    }
                    else
                    {

                    }
                }
            }
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }
    }
}

 


Answers (5)