简体   繁体   中英

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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM