Assign a string value a null date in one line?

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

Hello,

I'm pulling dates from a dataset and then assigning that to a textbox.

These dates can be null, that is where my problem comes in at. I guess there
is no such thing as an "empty date", I'll have to deal with the nulls, but
I'm having trouble assigning them.

I'd prefer to do it in one line of code if at all possible, just because I'm
assigning like 80 fields out of the dataset, and would rather not have that
many if then else's out there.

Does anyone have a good way to take a null value from a dataset and assign
it to a string value?

Thanks,
--Michael
 
Michael, it's not necessarily a great way to do things, but depending on the
circumstances it's ok. You can ensure that no nulls come back by using the
IsNull function and assigning a default value of string.Empty of '' in SQL.

If you aren't using a Strongly Typed DataSet, you should be cool.
 
I looked at that too, but using isnull there results in the date being set
at '1/1/1900' in the datasource. Yet another thing to check for.. :) I am
using a typed dataset, maybe I should experiment with the NullValue
attribute in the definition file.
 
Hey this worked (all in one line), I didn't realize you could do this kind
of construct in VB.net


If ds.datatable(0).IsmydatefieldnameNull Then mystring = String.Empty Else
mystring = ds.datatable(0).mydatefieldname
 
Back
Top