How to check for query field length

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the follow asignment: txtDescription.Text = dtrSlb("slbDesc2")
If the field returned is Null i get a run time error.
I can check for if (dtrSlb("slbDesc1").GetType.ToString() = "System.DBNull")
then .... But there has to be a better way.
Aslo what's the best way t oget the length of the returned field from a query?
Thanks for help on this simple question
kes
 
Hi,

In VB.NET you can use IsDBNull function, or generally Convert.IsDBNull to
check if it is DBNull or if working with DataReader then its own IsDbNull
method.

You could create general class for the mostly used types to convert it to
certain type and check for null. For example NZ.GetString(argument) which
returns String.Empty if argument is DBNull and otherwise return the value
converted to string. You could pass fields straight from DataReader or
DataSet to this method to perform the conversion for UI.
 
thank you that's it!!!!!
kes

Teemu Keiski said:
Hi,

In VB.NET you can use IsDBNull function, or generally Convert.IsDBNull to
check if it is DBNull or if working with DataReader then its own IsDbNull
method.

You could create general class for the mostly used types to convert it to
certain type and check for null. For example NZ.GetString(argument) which
returns String.Empty if argument is DBNull and otherwise return the value
converted to string. You could pass fields straight from DataReader or
DataSet to this method to perform the conversion for UI.
 
Back
Top