Working with Dataset and Null Values
Hi Guys
Im pulling lots of data from datasets and placing the values into text fields on my vb form. Im getting a lot of errors relating to null values. What i want to know is if there a simple way of setting a value to the null value reference. Im aware i can add if statements as i already have for various sections but dont want to have to add an if statement for each null value pulled out.
Any help appreicated.
Re: Working with Dataset and Null Values
Welcome to VBForums ! :)
If you are using strongly typed dataset (xsd), in dataset designer right click the data column, goto properties. In the properties window see the "NullValue" property. Set it the way you like.
You can set a variable to DBNull by assigning it DBNull.Value.
Also, please do a google search for "IsDbNull", "Nullable Data Type", "difference between dbnull and nothing".
Re: Working with Dataset and Null Values
Quote:
Originally Posted by
iPrank
Welcome to VBForums ! :)
If you are using strongly typed dataset (xsd), in dataset designer right click the data column, goto properties. In the properties window see the "NullValue" property. Set it the way you like.
You can set a variable to DbNull by alligning it [b]DbNull.Value[b].
Also, please do a search for "IsDbNull", "Nullable Data Type".
Hi Mate yes its an xsd dataset, the field in question wont allow me to set is as empty. Ive tried adding the following line of code to check and assign the value but im getting an error message.
IIf (IsDBNull(Me.DataSet11.Staff.FindByPayref(EmpVar).Forename1, string.Empty, "Test")
Its stating to many arguement for IsDBNull, ill have a search on the two criteria you just added now.
Re: Working with Dataset and Null Values
If the field is an Identity field or NotNull field, you may have problem. Try setting "AllowDbNull=True" or remove the constraints/relation from the dataset.
(I'm not 100% sure about this on XSD, but got similar problem in untyped dataset)