2
Reply

need validation for when datetimepicker finds no results.

James Johnson

James Johnson

Mar 9 2016 4:31 PM
378
 


I am currently working on a SQL C# windows form application and have made a form where users can search through delivery dates in the database by selecting a date range from two datetime pickers called DTpstr and DTPEn, when dates are found they will then be displayed in a datagridview for the users to see.  DTpstr is the start date and DTPEn is the end date. 

 
How would i add a basic messagebox showing that no deliverydates have been found from the database when the user has found no results from a search made between the two datetimepickers.
 
private void button2_Click(object sender, EventArgs e)
{
SqlDataAdapter SDA = new SqlDataAdapter("SELECT * FROM [Order] WHERE DeliveryDate BETWEEN '" + DTpstr.Text + "' AND '" + DTPEn.Text + "' ", con);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SDA.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (!row.IsNewRow)
lbResults.Items.Add(row.Cells[0].Value.ToString() + " " + row.Cells[1].Value.ToString() + " " + row.Cells[2].Value.ToString());
}
}
{
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
this.chart1.Series["Deliverytimes"].Points.AddXY(dataGridView1.Rows[i].Cells[0].Value.ToString(), Convert.ToDateTime(dataGridView1.Rows[i].Cells[2].Value.ToString()));

Answers (2)