You created the OleDbDataAdapter
only with the Select
command:
adp1 = new OleDbDataAdapter(cmd1);
OleDbDataAdapter
requires valid Update
, Insert,
Delete
commands that will be used to save such data:
adp1.Update(dt);
You just need to use OleDbCommandBuilder
, which will generate the commands for you:
adp1 = new OleDbDataAdapter(); adp1.SelectCommand = cmd1; // cmd1 is your SELECT command OleDbCommandBuilder cb = new OleDbCommandBuilder(adp1);
EDIT
Since you change the Select OleDbDataAdapter
at runtime to swap, you need to initialize every time you save data:
private void button1_Click(object sender, EventArgs e) { try { adp1.SelectCommand = cmd1;
source share