Reputation: 355
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
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