Why not use the DataTable as the DataSource of the DataGridView?
Either directly or via a BindingSource.
It will make your code a bit simpler.
private void btnsearch_Click(object sender, EventArgs e)
{
try
{
DateTime frmdate = Convert.ToDateTime(dtpfrom.Text);
DateTime todate = Convert.ToDateTime(dtpto.Text);
string datetimefrm = frmdate.ToString("yyyy-MM-dd 00:00:00.000");
string datetimeto = todate.ToString("yyyy-MM-dd 00:00:00.000");
if (ckaprov.Checked == true)
{
cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Proc_GetIndentBetweenDate";
cmd.Parameters.Add(new SqlParameter("fromDate", datetimefrm));
cmd.Parameters.Add(new SqlParameter("@toDate", datetimeto));
cmd.Connection = con;
table = new DataTable();
adapter = new SqlDataAdapter(cmd);
adapter.Fill(table);
dataGridView1.DataSource = table.DefaultView;
}
else
{
MessageBox.Show("No open indents found , Please check Approved.");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Also, hiding an exception is usually a bad idea, especially during debugging.