Verifing is field is NULL
Hello,
I am trying to populate a form from a SQL server table that allows null values. So after I read in a record I am trying to check if the field value is null so that I can assign "" to the textbox on the form. In the example below, if there is a value in the vendor field it works fine. If there is a NULL value in the vendor field it does not assign "", it errors. Can someone tell me why my code is not working here?
Imports System.Data.SqlClient
__________________________________
cmSQL = New SqlCommand(strSQL, cnSQL)
drSQL = cmSQL.ExecuteReader()
If drSQL.Read() Then
If IsDBNull(drSQL.Item("vendor").ToString()) Then
txtvendor.Text = ""
Else
txtvendor.Text = drSQL.Item("vendor").ToString()
End If
End If
Thanks,
FoxT
OK, here is what happened.
It turned out that the problem was here in this code below. Not my previous code.
If IsDBNull(drSQL.Item("received").ToString()) Then
txtreceived.Mask = ""
txtreceived.CtlText = ""
txtreceived.Mask = "##/##/####"
Else
****This line here*****
txtreceived.CtlText = VB6.Format(drSQL.Item("received").ToString(), "MM/DD/YYYY")
End If
My solution was to delete this line of code until I find another way to read in a date field and format it to short date in order to pass the value to a MaskEdit TextBox on my form. I would be greatly interested in how others are reading in date values and formatting them for textboxes on data input forms.
FoxT
:)