Can anyone help me on how to avoid getting duplicated output on DataGridView. Here is the image Before change and the image After add/edit or delete.
Here is the loader for my DataGridView:
private DataTable data()
{
using (OleDbConnection con = new OleDbConnection(inventorydb))
{
using (OleDbCommand com = new OleDbCommand("Select * FROM Items",con))
{
con.Open();
OleDbDataReader reader = com.ExecuteReader();
items.Load(reader);
}
}
return items;
}
void reset()
{
connect.Close();
connect.ConnectionString = inventorydb;
connect.Open();
dataGridView1.DataSource = null;
dataGridView1.Update();
dataGridView1.Refresh();
dataGridView1.DataSource = data();
}
Add and save changes:
private void save_Click(object sender, EventArgs e)
{
if (mode == "a")
{
connect.Close();
connect.ConnectionString = inventorydb;
connect.Open();
sqlcommand.CommandText = "INSERT INTO Items (SerialID, Brand_Name, Item_Name,Item_Date) VALUES ('" + txtserial.Text + "','" + txtbrand.Text + "', '" + txtitem.Text + "', '" + date + "') ";
sqlcommand.Connection = connect;
OleDbDataReader reader = sqlcommand.ExecuteReader();
MessageBox.Show("Record(s) Saved", "Sample");
}
connect.Close();
reset();
}