Shovan Saha

Shovan Saha

  • NA
  • 321
  • 92.6k

This is my code but result is null.

May 6 2017 3:57 AM
Is any wrong here? 
 
private void btnSearch_Click(object sender, EventArgs e)
{
con = new OleDbConnection(conString);
var query = "SELECT * FROM LalData " +
" WHERE " +
"SuspenceAccount = @suspenceAccount " +
"AND " +
"PaymentDate BETWEEN @startDate AND @endDate ";
con.Open();
OleDbCommand cmd = new OleDbCommand(query, con);
cmd.Parameters.AddWithValue("@startDate ", DbType.Date).Value =
dtpStartDate.Value.ToShortDateString();
cmd.Parameters.AddWithValue("@endDate ", DbType.Date).Value =
dtpEndDate.Value.ToShortDateString();
cmd.Parameters.AddWithValue("@suspenceAccount ", DbType.String).Value =
comboBox2.SelectedItem.ToString();
adapter = new OleDbDataAdapter(cmd);
adapter.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0];
con.Close();
}

Answers (3)