0
Dim db As Database = DatabaseFactory.CreateDatabase()
    Dim sqlCommand As String = "CategoryListShow"
    Dim cmd As DbCommand = db.GetStoredProcCommand(sqlCommand)
    cmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int).Direction = ParameterDirection.Input)
    cmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int, 4).Value = CategoryIdTxt.Text.Trim())
    cmd.Parameters.Add(New SqlParameter("@CategoryResult", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output)
    Dim sqlReader As SqlDataReader = cmd.ExecuteReader()
    txtCategory.Text = cmd.Parameters("@CategoryResult").Value.ToString()
    sqlReader.Close()

I am calling a Stored Procedure "CategoryListShow". The Stored Procedure has two parameters one is ID which is the Input Parameter and CategoryResult is the output parameter. I am trying to display the value of the output parameters onto this textbox txtCategory.Text.

Error : Yellow screen saying this

The SqlParameterCollection only accepts non-null SqlParameter type objects, not Boolean objects.

Please guide me.

4

2 回答 2

3

在设置@ID 值的行中,将其更改为此。

cmd.Parameters@("ID").Value = CategoryIdTxt.Text

您无需再次声明它。只需设置它的值。我发现处理参数的最佳方法是使用以下两行代码

cmd.Parameters.Add(New SqlParameter("@ProdID", Data.SqlDbType.Int)).Direction = ParameterDirection.Input
cmd.Parameters("@ProdID").Value = tProdID'obviously don't need this if it is an Output Param
于 2013-07-12T12:16:56.200 回答
1

错误一:

cmd.Parameters.Add(New SqlParameter("@ID", SqlDbType.Int)
                              .Direction = ParameterDirection.Input)

您正在尝试将new SqlParameter(...).Direction = ParameterDirection.Input布尔值(这是一个比较)的结果添加到cmd.Parameters.

您必须先初始化参数,然后将它们添加到集合中:

错误2:

您要添加@ID两次。

错误 3:

因为@ID被声明为,所以在将其分配给参数之前Int,它的值应该是 int => convert CategoryIdTxt.Textto类型。Int


您可以按如下方式解决这些问题:

''' @ID '''
Dim param As SqlParameter = New SqlParameter("@ID", SqlDbType.Int, 4)
param.Direction = ParameterDirection.Input
param.Value = Int32.Parse(CategoryIdTxt.Text);
cmd.Parameters.Add(param);

''' @CategoryResult '''
param = New SqlParameter("@CategoryResult", SqlDbType.VarChar, 50)
param.Direction = ParameterDirection.Output
cmd.Parameters.Add(param);
于 2013-07-12T11:34:18.497 回答