none
converting a bit to a boolean returns a false everytime RRS feed

  • Question

  • Would someone resolve this syntax for me

     

    foreach (TKData.VfSIF001Row rows in tblInsp)
                    {
                        Validate();
                        rows.EndEdit();

                        if (rows.RowState == DataRowState.Modified)
                        {                       
                            string name = Convert.ToString(rows.Name);
                            string number = Convert.ToString(rows.Number);
                            string location = Convert.ToString(rows.Location);
                            string inspdateNew = Convert.ToDateTime(rows "InspDateNew"]).ToString("dd-MMM-yyyy");
                            bool partial = Convert.ToBoolean(rows.PartialInspection);

     

    Not sure why this isn't working but the the rows.PartialInspection is always false

    Monday, August 20, 2007 2:54 PM

Answers

  • You need to inspect generated code behind dataset. If in your database, type of column is boolean, then also in the dataset table, column type should be boolean, so no conversion is necessary. About null values, that is another goodie of typed dataset. Every column in datatable has a property named AllowDbNull. If this property is set to true, then automatically by dataset code generator you will get a method named "Is" + ColumnName + "Null". So if column is named Test and have a AllowDbNull = true, then you will automatically have a method named IsTestNull() which should be used. Aslo you need to inspect what you have in the get accessor of column property to see what will happend if you read this property(column) and that property have null value. You will see that in that case an exception is raised indicating null value. That means that for all columns that alow null values, you will first examine does that property contains value using IsColumnNameNull methods for all of them, and only if they contain values, then you can read them.

     

    Monday, August 20, 2007 6:41 PM

All replies

  • You need first to inspect what is PartialInspection in the dataset, and check it's type. If the type for this column is boolean then conversion is not necessary and you will not have any problems. Also other conversions should be removed if the type  of columns is the same as your variables.

    Monday, August 20, 2007 5:54 PM
  • The type in the db is a Bit.  Hence the need to convert it.  Is there also a way to check if the value is null in that column as if I leave it as a NULL in the db it throws and exception.  so I need to check if the value null as well as convert it.  Maybe a tryparse might work?

     

    I'll check to see if the others are the same type though.

     

    Thanks,

    C

     

    Monday, August 20, 2007 6:04 PM
  • You need to inspect generated code behind dataset. If in your database, type of column is boolean, then also in the dataset table, column type should be boolean, so no conversion is necessary. About null values, that is another goodie of typed dataset. Every column in datatable has a property named AllowDbNull. If this property is set to true, then automatically by dataset code generator you will get a method named "Is" + ColumnName + "Null". So if column is named Test and have a AllowDbNull = true, then you will automatically have a method named IsTestNull() which should be used. Aslo you need to inspect what you have in the get accessor of column property to see what will happend if you read this property(column) and that property have null value. You will see that in that case an exception is raised indicating null value. That means that for all columns that alow null values, you will first examine does that property contains value using IsColumnNameNull methods for all of them, and only if they contain values, then you can read them.

     

    Monday, August 20, 2007 6:41 PM
  •  

    Boban,

     

    Thanks for your help it did lead me to discover a resolution.  The property of the column in the datagrid is where I was actually able to set the defaultfalse value, defaulttrue value and what to do if the column contains a NULL.

     

    Thanks for leading me down this path.  BTW, did I say that I hate db's with null values

     

    Regards,

    C

    Tuesday, August 21, 2007 3:02 AM