Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Good news everyone! The Boards.ie Subscription service is live. See here: https://subscriptions.boards.ie/

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