dotnetnubie
Member
- Joined
- Jun 4, 2005
- Messages
- 9
- Programming Experience
- 10+
Hello all. I am experiencing problems with DbNull values being returned from a data request. In fact, I can't seem to even test for the problem without errors. The process starts with a parent form displaying a datagrid of selections. Clicking a link on that page invokes the child form, sending a URL variable as the parameter. In the page load function, a query is performed and text boxes on the form are set with values from the selected row of the database. But, if a field in the database has a DbNull value, I receive an error. In the example code below, PHONE_B is the field with the DbNull value. I try to test for the null value, but it errors-out on that as well (I will bold the test statement for clarity).
I hate to have to test every field for a Dbnull value. Is there an easy way to handle this?
-- START CODE
PrivateSub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
Dim MyUrl As Uri = Request.Url
Dim emp_id AsString
Dim dsrow AsInteger
Me.company_logo.ImageUrl = company_logo_path
Dim tmp_string AsString
Dim tmp_null AsBoolean
'Put user code to initialize the page here
emp_id = Mid(MyUrl.Query, 2)
'Me.name.Text = emp_id
OnErrorGoTo 0
Me.Ds_fpersonnel_detail1.Clear()
Me.SqlSelectCommand1.CommandText = "SELECT COMPANY_ID, CATEGORY, EMP_ID, NAME, ADDRESS, CITY, STATE, ZIP, PHONE_H, PHONE_B, PHONE_F, EMAIL, POSITION, EMP_ID, COMPANY_EMP_ID, DATE_APPLIED, DATE_HIRED, DATE_TERMINATED, LOCATION from fs_personnel where COMPANY_ID = " & company_id & " and EMP_ID = " & emp_id
Me.SqlDataAdapter1.Fill(Ds_fpersonnel_detail1)
Me.DataBind()
If Ds_fpersonnel_detail1.fs_personnel.Count > 0 Then
dsrow = CType(Session("RecordPos"), Integer)
Me.name.Text = Ds_fpersonnel_detail1.fs_personnel(dsrow).NAME
Me.address.Text = Ds_fpersonnel_detail1.fs_personnel(dsrow).ADDRESS
Me.city.Text = Ds_fpersonnel_detail1.fs_personnel(dsrow).CITY
Me.state.Text = Ds_fpersonnel_detail1.fs_personnel(dsrow).STATE
Me.zip.Text = Ds_fpersonnel_detail1.fs_personnel(dsrow).ZIP
Me.phone_h.Text = Ds_fpersonnel_detail1.fs_personnel(dsrow).PHONE_H
If Ds_fpersonnel_detail1.fs_personnel(dsrow).PHONE_B Is DBNull.Value Then
Me.phone_b.Text = ""
Else
Me.phone_b.Text = Ds_fpersonnel_detail1.fs_personnel(dsrow).PHONE_B
EndIf
tmp_string = Ds_fpersonnel_detail1.fs_personnel(dsrow).CATEGORY
If tmp_string = "1" Then
Me.DropDownList_category.SelectedValue = "1"
ElseIf tmp_string = "2" Then
Me.DropDownList_category.SelectedValue = "2"
ElseIf tmp_string = "3" Then
Me.DropDownList_category.SelectedValue = "3"
ElseIf tmp_string = "4" Then
Me.DropDownList_category.SelectedValue = "4"
EndIf
Me.Label3.Text = "HR Detail Page"
Else
Me.Label3.Text = "Record Not Found!"
EndIf
EndSub
-- END CODE
Thanks in advance,
dotnetnubie
I hate to have to test every field for a Dbnull value. Is there an easy way to handle this?
-- START CODE
PrivateSub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
Dim MyUrl As Uri = Request.Url
Dim emp_id AsString
Dim dsrow AsInteger
Me.company_logo.ImageUrl = company_logo_path
Dim tmp_string AsString
Dim tmp_null AsBoolean
'Put user code to initialize the page here
emp_id = Mid(MyUrl.Query, 2)
'Me.name.Text = emp_id
OnErrorGoTo 0
Me.Ds_fpersonnel_detail1.Clear()
Me.SqlSelectCommand1.CommandText = "SELECT COMPANY_ID, CATEGORY, EMP_ID, NAME, ADDRESS, CITY, STATE, ZIP, PHONE_H, PHONE_B, PHONE_F, EMAIL, POSITION, EMP_ID, COMPANY_EMP_ID, DATE_APPLIED, DATE_HIRED, DATE_TERMINATED, LOCATION from fs_personnel where COMPANY_ID = " & company_id & " and EMP_ID = " & emp_id
Me.SqlDataAdapter1.Fill(Ds_fpersonnel_detail1)
Me.DataBind()
If Ds_fpersonnel_detail1.fs_personnel.Count > 0 Then
dsrow = CType(Session("RecordPos"), Integer)
Me.name.Text = Ds_fpersonnel_detail1.fs_personnel(dsrow).NAME
Me.address.Text = Ds_fpersonnel_detail1.fs_personnel(dsrow).ADDRESS
Me.city.Text = Ds_fpersonnel_detail1.fs_personnel(dsrow).CITY
Me.state.Text = Ds_fpersonnel_detail1.fs_personnel(dsrow).STATE
Me.zip.Text = Ds_fpersonnel_detail1.fs_personnel(dsrow).ZIP
Me.phone_h.Text = Ds_fpersonnel_detail1.fs_personnel(dsrow).PHONE_H
If Ds_fpersonnel_detail1.fs_personnel(dsrow).PHONE_B Is DBNull.Value Then
Me.phone_b.Text = ""
Else
Me.phone_b.Text = Ds_fpersonnel_detail1.fs_personnel(dsrow).PHONE_B
EndIf
tmp_string = Ds_fpersonnel_detail1.fs_personnel(dsrow).CATEGORY
If tmp_string = "1" Then
Me.DropDownList_category.SelectedValue = "1"
ElseIf tmp_string = "2" Then
Me.DropDownList_category.SelectedValue = "2"
ElseIf tmp_string = "3" Then
Me.DropDownList_category.SelectedValue = "3"
ElseIf tmp_string = "4" Then
Me.DropDownList_category.SelectedValue = "4"
EndIf
Me.Label3.Text = "HR Detail Page"
Else
Me.Label3.Text = "Record Not Found!"
EndIf
EndSub
-- END CODE
Thanks in advance,
dotnetnubie