B
Big E
I'm using ASP.Net and SQL Server. I'm breaking up the Phone Number into 3
sections for a form. When the value is Null I recieve Cast from type
'DBNull' to type 'String' is not valid.
I'm using a Null checker as seen below. When using this without the Left or
Mid it will work.
Thanks.
txtWorkPhone1.Text =
StringNullHelper(Left(dsReg.Tables("tblProspect").Rows(0)("WorkPhone"), 3))
txtWorkPhone2.Text =
StringNullHelper(Mid(dsReg.Tables("tblProspect").Rows(0)("WorkPhone"), 4,
3))
txtWorkPhone3.Text =
StringNullHelper(Mid(dsReg.Tables("tblProspect").Rows(0)("WorkPhone"), 7,
4))
----------------------------------------------------------------------------
----------------------
Public Function StringNullHelper(ByVal obj As Object) As String
If IsDBNull(obj) Then Return String.Empty
Return obj.ToString()
End Function
sections for a form. When the value is Null I recieve Cast from type
'DBNull' to type 'String' is not valid.
I'm using a Null checker as seen below. When using this without the Left or
Mid it will work.
Thanks.
txtWorkPhone1.Text =
StringNullHelper(Left(dsReg.Tables("tblProspect").Rows(0)("WorkPhone"), 3))
txtWorkPhone2.Text =
StringNullHelper(Mid(dsReg.Tables("tblProspect").Rows(0)("WorkPhone"), 4,
3))
txtWorkPhone3.Text =
StringNullHelper(Mid(dsReg.Tables("tblProspect").Rows(0)("WorkPhone"), 7,
4))
----------------------------------------------------------------------------
----------------------
Public Function StringNullHelper(ByVal obj As Object) As String
If IsDBNull(obj) Then Return String.Empty
Return obj.ToString()
End Function