Kenshi Hemura
Kenshi Hemura

Reputation: 135

save checkbox value in access database with vb.net 2010 (wpf c#)

guy how can i insert the value of checkbox in access database or any database.

i tried any of this sql statement but it still give me error: OleDbException was Unhandled. Data type mismatch in criteria expression. and it's pointing to myData = myCommand.ExecuteReader();

note that allowviewpsr is a boolean type of field in ms access database or the one with YES/NO. :) chkviewpsr is mycheckbox

SQL = "UPDATE `RUsers` SET `allowviewpsr` = '" + chkviewpsr.IsChecked.Value + "' WHERE `idnum`= '" + txtblkuserid.Text  + "' AND `fullname`= '" + txtblkusername.Text + "'";

also this:

SQL = "UPDATE `RUsers` SET `allowviewpsr` = '" + chkviewpsr.IsChecked + "' WHERE `idnum`= '" + txtblkuserid.Text  + "' AND `fullname`= '" + txtblkusername.Text + "'";

and also this:

SQL = "UPDATE `RUsers` SET `allowviewpsr` = '" + chkviewpsr + "' WHERE `idnum`= '" + txtblkuserid.Text  + "' AND `fullname`= '" + txtblkusername.Text + "'";

and here's my connector:

myCommand.CommandText = SQL;
myCommand.Connection = MyNewOleDbConnection;
myAdapter.SelectCommand = myCommand;
myData = myCommand.ExecuteReader();

EDITED: hi anandkumar thanks for the quick replay i tried NonQuery but it gives same error as above

SQL = "UPDATE `RWMUsers` SET `allowviewpsr` = '" + chkviewpsr.IsChecked.Value + "' WHERE `idnum`= '" + txtblkuserid.Text  + "' AND `fullname`= '" + txtblkusername.Text + "'";
myCommand.CommandText = SQL;
myCommand.Connection = MyNewOleDbConnection;
myAdapter.UpdateCommand = myCommand;
myCommand.ExecuteNonQuery();

Snapshot of my Access Database :(

enter image description here

Upvotes: 0

Views: 4964

Answers (1)

andy
andy

Reputation: 6079

Instead of

myAdapter.SelectCommand = myCommand;
myCommand.ExecuteReader(); 

Use

myAdapter.UpdateCommand = myCommand;
myCommand.ExecuteNonQuery();

Reference:

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.updatecommand.aspx

Upvotes: 3

Related Questions