使用参数在 ASP.NET (VB) 中选择语句 - 错误:输入字符串的格式不正确

发布于 2024-08-28 08:10:12 字数 1868 浏览 4 评论 0原文

所以我在 VB 模块中有一些代码。当我使用在 where 语句中具有硬编码值的 SQL 语句运行此命令时,它会起作用。我现在尝试向模块添加参数,以便表单可以排除用户的输入,但我收到消息:输入字符串的格式不正确。

这是代码部分:

    objCon.Open()
    objCmd.Connection = objCon
    objCmd.CommandType = CommandType.Text
    objCmd.CommandText = sSQL

    objDataAdapter = New iDB2DataAdapter(objCmd)
    objDataSet = New DataSet
    objDataAdapter.Fill(objDataSet)

    sSQL = ""
    sSQL += "SELECT "
    sSQL += "    DIGITS(DDS#) AS STORE, "
    sSQL += "    DIGITS(DSKU) || DIGITS(DCHK) SKU, "
    sSQL += "    DORQ AS ORIGQTY, "
    sSQL += "    DQTY AS DISTQTY, "
    sSQL += "    DAKQ AS ACKQTY, "
    sSQL += "    CHAR(DDTI,ISO) AS DISTRIBUTIONDATE, "
    sSQL += "    DDC# AS DISTNO, "
    sSQL += "    DPIC AS PICKSHEET, "
    sSQL += "    DALC AS ALLOCNO, "
    sSQL += "    DSTS AS STATUS, "
    sSQL += "    CHAR(DPKI,ISO) AS PICKDATE, "
    sSQL += "    CHAR(DMNI,ISO) AS MANIFESTDATE, "
    sSQL += "    CHAR(DAKI,ISO) AS ACKDATE, "
    sSQL += "    CHAR(DASI,ISO) AS SHIPMENTDATE "
    sSQL += "FROM "
    sSQL += "    IPTSFIL.IPPNDST "
    sSQL += "WHERE "
    sSQL += "    DDS# = @STORENO AND "
    sSQL += "    DSKU = @SKU AND "
    sSQL += "    DCHK = @CHK "
    sSQL += "ORDER BY "
    sSQL += "    DISTRIBUTIONDATE DESC "

    objCmd.CommandType = CommandType.Text
    objCmd.CommandText = sSQL

    objCmd.Parameters.Add("@STORENO", iDB2DbType.iDB2Char, 5, "DDS#")
    objCmd.Parameters("@STORENO").Value = sStoreNo

    objCmd.Parameters.Add("@SKU", iDB2DbType.iDB2Char, 9, "DSKU")
    objCmd.Parameters("@SKU").Value = Mid(sSKU, 1, Len(sSKU) - 1)

    objCmd.Parameters.Add("@CHK", iDB2DbType.iDB2Char, 1, "DCHK")
    objCmd.Parameters("@CHK").Value = Right(sSKU, 1)

    objDataAdapter = New iDB2DataAdapter(objCmd)
    objDataSet = New DataSet
    objDataAdapter.Fill(objDataSet)

就像我说的,如果我用固定值替换参数,那么一切都会起作用。

So I have some code in a VB module. When I run this with the SQL statement having hard coded values in the where statement it works. I am now trying to add Parameters to the module so that the Form can except an Input from a user, but I am getting the message: Input string was not in a correct format.

Here is the section of code:

    objCon.Open()
    objCmd.Connection = objCon
    objCmd.CommandType = CommandType.Text
    objCmd.CommandText = sSQL

    objDataAdapter = New iDB2DataAdapter(objCmd)
    objDataSet = New DataSet
    objDataAdapter.Fill(objDataSet)

    sSQL = ""
    sSQL += "SELECT "
    sSQL += "    DIGITS(DDS#) AS STORE, "
    sSQL += "    DIGITS(DSKU) || DIGITS(DCHK) SKU, "
    sSQL += "    DORQ AS ORIGQTY, "
    sSQL += "    DQTY AS DISTQTY, "
    sSQL += "    DAKQ AS ACKQTY, "
    sSQL += "    CHAR(DDTI,ISO) AS DISTRIBUTIONDATE, "
    sSQL += "    DDC# AS DISTNO, "
    sSQL += "    DPIC AS PICKSHEET, "
    sSQL += "    DALC AS ALLOCNO, "
    sSQL += "    DSTS AS STATUS, "
    sSQL += "    CHAR(DPKI,ISO) AS PICKDATE, "
    sSQL += "    CHAR(DMNI,ISO) AS MANIFESTDATE, "
    sSQL += "    CHAR(DAKI,ISO) AS ACKDATE, "
    sSQL += "    CHAR(DASI,ISO) AS SHIPMENTDATE "
    sSQL += "FROM "
    sSQL += "    IPTSFIL.IPPNDST "
    sSQL += "WHERE "
    sSQL += "    DDS# = @STORENO AND "
    sSQL += "    DSKU = @SKU AND "
    sSQL += "    DCHK = @CHK "
    sSQL += "ORDER BY "
    sSQL += "    DISTRIBUTIONDATE DESC "

    objCmd.CommandType = CommandType.Text
    objCmd.CommandText = sSQL

    objCmd.Parameters.Add("@STORENO", iDB2DbType.iDB2Char, 5, "DDS#")
    objCmd.Parameters("@STORENO").Value = sStoreNo

    objCmd.Parameters.Add("@SKU", iDB2DbType.iDB2Char, 9, "DSKU")
    objCmd.Parameters("@SKU").Value = Mid(sSKU, 1, Len(sSKU) - 1)

    objCmd.Parameters.Add("@CHK", iDB2DbType.iDB2Char, 1, "DCHK")
    objCmd.Parameters("@CHK").Value = Right(sSKU, 1)

    objDataAdapter = New iDB2DataAdapter(objCmd)
    objDataSet = New DataSet
    objDataAdapter.Fill(objDataSet)

Like I said, if I subsitute the Parameters for fixed values it all works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾北清歌寒 2024-09-04 08:10:12

您连接到什么数据库?某些数据库不支持命名参数。

有关替代语法,请参阅带参数的 AS400 SQL 查询

What database are you connecting to? Some databases don't support named parameters.

See AS400 SQL query with Parameter for alternate syntax.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文