SubSonic Forums
All Your Database Are Belong To Us

Updating boolean does not update

Latest post 11-11-2008 8:24 PM by martin1b. 3 replies.
  • 11-09-2008 11:06 PM

    Updating boolean does not update

    Hi-

    I have an update to a row where I'm updating several fields, one of them being a boolean / bit. All of the other rows update fine. The boolean field doesn't update.

    Any thoughts?

    TIA!

    Here is the code I'm using:

     

                    TblVehicle t = new TblVehicle();
                    if (bolAdd == false)
                    {
                        //doing this to work around bug for updates
                        t.IsNew = false;
                        t.MarkOld();
                        t.IsLoaded = true;
                        t.VehicleID = intVehicleID;  //primary key
                    }

                    t.VehicleCategoryID = Convert.ToInt16(cboCategory.SelectedValue);
                    t.VehicleLocationID = Convert.ToInt16(cboLocation.SelectedValue);
                    t.VehicleUnitNumber = txtUnitName.Text;
                    t.VehicleYear = Convert.ToInt16(txtYear.Text);
                    t.VehicleMake = txtMake.Text;
                    t.VehicleModel = txtModel.Text ;
                    t.VehicleCapacity = Convert.ToInt16(txtCapacity.Text);
                    t.VehicleNotes = txtNotes.Text;

    //**********   here is the section I'm having issues with
                   // t.VehicleActive = Convert.ToBoolean(cbActive.Checked);
                    t.VehicleActive = false;


                    t.LastModBy = clsGlobals.gstrCurrentUser;
                    t.LastModDate = DateTime.Now;
                    t.Save(clsGlobals.gstrCurrentUser);
                    MessageBox.Show("Record Saved", clsGlobals.gstrApplicationName);

     

     

     

  • 11-11-2008 6:12 AM In reply to

    Re: Updating boolean does not update

    I cant say I have tested your scenario as I am using Repository but I am updating boolean/bits without any issues.

    Are you using latest SVN version ?

    Have you had a look at the SQL being recieved by the database (eg Profiler in SQL Server) ?

    Have you stepped into Subsonic ? I'd be looking at the dirtycolumns collection to see if VehicleActive is being added when you change the value.

     

     

  • 11-11-2008 2:16 PM In reply to

    Re: Updating boolean does not update

    Reply |Contact |Answer

    When you create a new instance of your object, the VehicleActive is set to false by the constructor of the Boolean type (A boolean type always defaults to false).  Then when you try to set it to be false, subsonic sees that it is already false and doesn't mark the column as Dirty.

    To get around this problem, I load the object first then assign values:

     

                    TblVehicle t = new TblVehicle(intVehicleID);   //this will load the object and set VehicleActive to be what it currently is in the database

    .....

     

    t.VehicleActive = Convert.ToBoolean(cbActive.Checked);   //now if the database has true and I set t to false, subsonic will save it

    ...

     

     

  • 11-11-2008 8:24 PM In reply to

    Re: Updating boolean does not update

    Hey- That worked like a charm!

    I don't quite understand why the boolean value isn't set to vehicle active value as subsonic reads the database and why setting the constructor param to the primary key. Does it effectively have subsonic read the row and set it to current record? Then if you don't specify the current key,  as it's creating instances of the values to update per column, it's generating the SQL and compares what you're updating and because boolean defaults to false it considers that value to not have changed so it doesn't create the sql to update it?  I'd be interested in knowing more if you could go more into it. If not, I'm just happy it works!!!

    THANK YOU!!!!!

Page 1 of 1 (4 items) | RSS