Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

c# inserting boolean into access yes/no field

  • 17-01-2008 05:09PM
    #1
    Registered Users, Registered Users 2 Posts: 872 ✭✭✭


    Hi,

    im trying to insert the value of a checkbox (true,false) into an access db.

    The datatype for the column is Yes/No type.

    when i try to insert this i get : Data type mismatch in criteria expression

    im am setting the variable like
    bool filled = chkFilled.Checked;
    

    and the sql is normal stuff but it's not working.

    Any ideas ?

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Post the sql code, I'd make an educated guess as to that being the cause of the error.


  • Registered Users, Registered Users 2 Posts: 872 ✭✭✭grahamor


    Here is what i have so far, if i remove the filled and active lines from the sql it works.
            bool filled = chkFilled.Checked;
            bool active = chkActive.Checked;
            
    
            string sql = "UPDATE jobs SET ";
            sql += "[type]='" + type + "',";
            sql += "[ref]='" + reference + "',";
            sql += "[title]='" + title + "',";
            sql += "[desc]='" + description + "',";
            sql += "[location]='" + location + "',";
            sql += "[salary]='" + salary + "',";
            sql += "[posted]='" + date + "',";
            sql += "[filled]='" + filled + "',";
            sql += "[active]='" + active + "'";
            sql += " WHERE id=" + id + "";
    
            connect.connectDb(sql);
    

    Thanks


  • Registered Users, Registered Users 2 Posts: 610 ✭✭✭nialo


    Your passing your boolean values as strings. This is what is causing the problem i think.

    sql += "[filled]=" + filled + ",";
    sql += "[active]=" + active + "";


  • Moderators, Society & Culture Moderators Posts: 9,688 Mod ✭✭✭✭stevenmu


    I think you're problem is with the apostrophes, they denote that you're trying to put a string value into the field, so it's trying to update those fields with either the word "true" or the word "false" as opposed to the the yes/no value. Try it with the lines
    sql += "[filled]=" + filled + ",";
    sql += "[active]='" + active + "";


  • Registered Users, Registered Users 2 Posts: 872 ✭✭✭grahamor


    Thanks guys, that solved it.


  • Advertisement
Advertisement