Null Checker

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top