If dr.Read Then
mtCompareWeek.Text = dr("Week").ToString()
End If
我的访问数据库中的值为03
..但它只显示为3.如何在文本框中输入“03”?
* CStr
也不起作用。
答案 0 :(得分:4)
您应该使用format string
mtCompareWeek.Text = String.Format("{0:D2}", dr("Week"))
答案 1 :(得分:1)
How to: Pad a Number with Leading Zeros
int indexOfColumn = dr.GetOrdinal("Week");
mtCompareWeek.Text = dr.GetInt32(indexOfColumn).ToString("D2")
mtCompareWeek.Text = dr.GetInt32(indexOfColumn).ToString().PadLeft(2, "0"c)
答案 2 :(得分:1)
您可以使用String重载来指定位数:
If dr.Read Then
mtCompareWeek.Text = dr("Week").ToString("00")
End If
或者您可以使用String.Format:
If dr.Read Then
mtCompareWeek.Text = String.Format("{0:00}", dr("Week"))
End If