我是使用asp.net的新手我收到了“从字符串转换”ACECATN000001“输入'整数'无效的错误。”任何人都可以帮我解决这个问题吗?提前谢谢:D
If lbl_productcatcode.Text = "ACECATN000001" Then
txt_productcode.Text = Format(CInt(rdr.Item(0).ToString) + 1, "1000000")
End If
End If
cmd1.Connection.Close()
End Sub
答案 0 :(得分:1)
你已经发布了一些代码,但没有说出哪一行有错误,我认为是这一行:
cmd1.CommandText = "Select CategoryID from CategoryTable where ProductCategory = '" & DropDownList1.Text & "'"
如果CategoryId
上的CategoryTable
列的类型为integer
,则无法将其与字符串值进行比较。我猜你需要使用绑定到DropdownList的项目的ID,IIRC下拉列表中应该有一个SelectedValue属性,你可以使用它。
cmd1.CommandText = "Select CategoryID from CategoryTable where ProductCategory = " & DropDownList1.SelectedValue
注意单引号的缺失,因为您将在sql语句中注入int
值。
答案 1 :(得分:1)
首先:CInt(s)
将s
(s
作为字符串)转换为整数,仅在s
包含仅数字时有效(否)字母)。
在这一行:
txt_productcode.Text = Format(CInt(rdr.Item(0).ToString) + 1, "1000000")
您正在尝试将rdr.Item(0).ToString
转换为整数。根据你的代码,
rdr.Item(0).ToString
返回包含字母的"ACECATN000001"
,因此无法转换为整数。
你究竟想在那条线上做什么?