0

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

7
  • there is some bad practice in this code ;) you should read about query injection and how to avoid it. Commented Oct 30, 2012 at 6:09
  • can you give me sample on how can i create a right sql statement... thanks :( Commented Oct 30, 2012 at 6:17
  • @KenshiHemura, Please upload the table constraints and column types of "RWMUsers" Commented Oct 30, 2012 at 6:20
  • @KenshiHemura use Parameters to deal with variables in your sql queries. Commented Oct 30, 2012 at 7:40
  • @Felice Pollano thanks for the reply.. im sorry im not that good in c#.. can you give me an example if you dont mind. thanks :( Commented Oct 30, 2012 at 7:50

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.