g_shockTan
g_shockTan

Reputation: 355

ASP.Net VB SqlDataReader Format

I have a SqlDataReader that reads data from the database. How can I format the phone number to return as (123) 456-7890 instead of 1234567890 on my aspx page? My reader as follow:

txtFaxPhone.Text = reader("FaxPhone").ToString()

Upvotes: 0

Views: 661

Answers (1)

Ann L.
Ann L.

Reputation: 13965

Try something like this:

If reader.IsDbNull(reader.GetOrdinal("FaxPhone"))
   txtFaxPhone.Text = String.Empty
Else
   txtFaxPhone.Text = String.Format("(000) 000-0000", reader("FaxPhone"))
End If

Note: this assumes your phone number is a number. If it's a string, you'll have to substring it.

Upvotes: 1

Related Questions