Bound to MySQL Bit Column Question

6 posts, 0 answers
  1. Bkoenig
    Bkoenig avatar
    11 posts
    Member since:
    Jun 2013

    Posted 12 Jul 2013 Link to this post

    Hello,

    I have a table in a MySQL database that is getting hit via a Stored Procedure inside of a MySQL database.  The column type is a BIT(1) which according to the MySQL documentation is the correct way to implement a Boolean field into the database.  I don't really want to hard code the columns in to allow for some flexibility.  I would hate to have to update this GUI every time I add something new to the database.

    I went to one of the BIT columns that are located in the RadGridView and it appears to be an Numeric column because the range of accepted values is -79228162514264337593543950335 to 79228162514264337593543950335.   Not to sound like a wise guy, but putting anything other than 0 or 1 into a BIT(1) column will cause the database to have an aneurysm.

    Any help is much appreciated.
  2. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 17 Jul 2013 Link to this post

    Hi Brendon,

    Thank you for writing.

    In your case you will have to change the column type in RadGridView by deleting the numeric column and adding a checkbox column bound to the BIT(1) field. Here is how to do that:
    radGridView1.Columns.RemoveAt(1); //where 1 is the index of the numeric BIT column
     
    GridViewCheckBoxColumn col = new GridViewCheckBoxColumn();
    radGridView1.Columns.Add(col);
    col.FieldName = "testColumn"; //where testColumn is the name of the BIT field

    Please give this approach a try and let me know how it works for you.
     
    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. Bkoenig
    Bkoenig avatar
    11 posts
    Member since:
    Jun 2013

    Posted 17 Jul 2013 Link to this post

    Hello Stefan,

    Is this the only solution currently?  I was hoping for a solution that would be less static.

    Just as a side note, if this is just a bug in Q2 2013, I think this should be added to the list for Q3 2013.  If its not a feature currently, it would be somewhat of a useful feature because it would eliminate code such as the code mentioned.  Especially since I have a list of 16 Bit Columns that I would have to hard code just for one gridview.

    Thank you,
    Brendon
  4. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 19 Jul 2013 Link to this post

    Hi Brendon,

    This is not a bug, it is how RadGridView works. The BIT field in MySQL is a numeric field and RadGridView creates a numeric column for it when generating the columns automatically. As you want to interpret the field in a different manner, you have to replace the column with the one you want.

    I hope that you find this information useful.
     

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. Bkoenig
    Bkoenig avatar
    11 posts
    Member since:
    Jun 2013

    Posted 19 Jul 2013 Link to this post

    Hello Stefan,

    Thank you for that insight.  Doing research into that information, the BIT is stored as the numeric data type of TINYINT(1).  This leads me to a related question.  Why is the RadGrid column allow such a large number into such a column.

    Thank you
  6. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 24 Jul 2013 Link to this post

    Hi,

    Whem the grid detects a numeric value, by default it creates GridViewDecimalColumn which has a default DataType of decimal, hence the large number observed.

    I hope you find this information useful.
     

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top