Search code examples
c#ms-accessoledb

How do I update a Microsoft Access database record to true. C#


This is the code I have written so far. I know it connects to the database fine and I don't get any errors when running it. The only problem is that it doesn't update the yes/no field to true. I have also changed the format of the yes/No field to true/false.

Current Code:

                OleDbCommand cmd = new OleDbCommand();
            cmd.CommandType = CommandType.Text;
            con = new OleDbConnection();
            con.ConnectionString = DBaseConn.ConnectionString;
            cmd.Parameters.AddWithValue("@status",OleDbType.Boolean).Value = _status; //_status = true
            cmd.Parameters.AddWithValue("@Idnumber", _DeliID); //_DeliID = 5810
            cmd.CommandText = "UPDATE TblDelivery SET Assigned = '@status' WHERE DeliveryID=@Idnumber";
            cmd.Connection = con;
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

Solution

  • try to assign value in your commandtext without quote.

    cmd.CommandText = "UPDATE TblDelivery SET Assigned = @status WHERE DeliveryID=@Idnumber";