当我使用" 000" 将数字保存到我的mysql数据库时,它只变为" 0"
例如,我的数据就是这个。
姓名:Daisy Johnson>
年龄:23
TIN ID:123-456-789-000
当我将它保存在我的数据库中时,它就像这样。
姓名:Daisy Johnson
年龄:23
TIN ID:123-456-789-0
有什么建议吗?
Dim sup1 As String = Val(txttin1.Text)
Dim sup2 As String = Val(txttin2.Text)
Dim sup3 As String = Val(txttin3.Text)
Dim sup4 As String = Val(txttin4.Text)
Dim tinid As String = sup1 + sup2 + sup3 + sup4
tinid = sup1 + "-" + sup2 + "-" + sup3 + "-" + sup4
答案 0 :(得分:4)
更改
Dim sup4 As String = Val(txttin4.Text)
要
Dim sup4 As String = txttin4.Text.Trim()
(对于所有sup变量)
Val从字符串返回一个数字。见Val Function
更好的是,如果你需要数字有三位数,你可以格式化字符串。 Val在这里可以告诉编队,这是一个数字。
Dim tinid As String = String.Format(
"{0:000}-{1:000}-{2:000}-{3:000}",
Val(txttin1.Text),
Val(txttin2.Text),
Val(txttin3.Text),
Val(txttin4.Text))
因此,如果用户输入“45”,则将其格式化为“045”。您还应该首先对输入执行一些验证,以确保用户实际在TextBox中输入了一个数字。
答案 1 :(得分:1)
根据您使用此代码的评论:
Dim sup1 As String = Val(txttin1.Text)
Dim sup2 As String = Val(txttin2.Text)
Dim sup3 As String = Val(txttin3.Text)
Dim sup4 As String = Val(txttin4.Text)
Dim tinid As String = sup1 + sup2 + sup3 + sup4
tinid = sup1 + "-" + sup2 + "-" + sup3 + "-" + sup4
首先,为什么你给tinid
一个值而你只是不使用它然后设置另一个值?
其次,Val
函数会将您的表达式转换为Double
,这就是删除零的原因。
您的代码应如下所示:
Dim sup1 As String = txttin1.Text
Dim sup2 As String = txttin2.Text
Dim sup3 As String = txttin3.Text
Dim sup4 As String = txttin4.Text
Dim tinid As String = sup1 + "-" + sup2 + "-" + sup3 + "-" + sup4
最后,您的问题与mysql