|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Checking for NullsHi
Using VB.net 2005. In my xsd file, I set the Null value for a field called Description to "X".However, when I fill the datatable from the access database, if there is nothing in the Description field, it is still System.DBNull. 1) What must I change in the XSD file to have the null values replaced with X? 2) In code, how do I check if a field is null? Comparing to System.DBNull isn't allowed. Thanks Vayse 1) nullValue must be equal to "_empty" and you must set a default value
of "X" for the column. If you're using the property window, set the NullValue property to (Empty) and DefaultValue property to "X". http://msdn.microsoft.com/library/en-us/cpguide/html/cpconusingannotationswithtypeddataset.asp?frame=true 2) You must use the IsFieldXYZNull() method of the column value to determine if the value is System.DBNull. MyStronglyTypedDataSet.MyStronglyTypedDataTable dtData = myDataLayer.SelectAll(); foreach (MyStronglyTypedDataSet.MyStronglyTypedRow drRowData in dtData.Rows) { ... if (drRowData.IsFieldXYZNull() == false) string myData = drRowData.FieldXYZ; ... } } Bill 1) nullValue must be equal to "_empty" and you must set a default value
of "X" for the column. If you're using the property window, set the NullValue property to (Empty) and DefaultValue property to "X". http://msdn.microsoft.com/library/en-us/cpguide/html/cpconusingannota... 2) You must use the IsFieldXYZNull() method of the column value to determine if the value is System.DBNull. MyStronglyTypedDataSet.MyStronglyTypedDataTable dtData = myDataLayer.SelectAll(); foreach (MyStronglyTypedDataSet.MyStronglyTypedRow drRowData in dtData.Rows) { ... if (drRowData.IsFieldXYZNull() == false) string myData = drRowData.FieldXYZ; ... } } Bill |
|||||||||||||||||||||||