Shovan Saha

Shovan Saha

  • NA
  • 321
  • 91.8k

Duplicate value in datagridview pressing show button

May 19 2017 5:39 PM

This is My Code in C# and visual studio 2015: When I select from combobox and two dates and press Show button, If I found 3 data, when I press next time the Show button then I get 6 data, and next time 9 data .......... . I do not want to get duplicate data in datagridview. Please help me.

private void btnShow_Click(object sender, EventArgs e)

{

con = new OleDbConnection(conString);

var query = "SELECT * FROM LalData " +

" WHERE " +

"SuspenceAccount = @suspenceAccount1 " +

"AND " +

"(PaymentDate BETWEEN @fromDate AND @toDate)";

con.Open();

OleDbCommand cmd = new OleDbCommand(query, con);

cmd.Parameters.AddWithValue("@suspenceAccount1 ", DbType.String).Value = comboBoxSelectSuspenseAccount.Text.ToString();

cmd.Parameters.AddWithValue("@fromtDate ", DbType.Date).Value =

dtpFromDate.Value.ToShortDateString();

cmd.Parameters.AddWithValue("@toDate ", DbType.Date).Value =

dtpToDate.Value.ToShortDateString();

adapter = new OleDbDataAdapter(cmd);

adapter.Fill(dt);

dataGridView1.DataSource = dt;

dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0];

con.Close();

}


Answers (1)