所以我在 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)
就像我说的,如果我将参数替换为固定值,那么一切正常。