Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
671 views
in Technique[技术] by (71.8m points)

ado.net - Parameter object is improperly defined vb.net mariadb

I'm getting error from this line cmd.Parameters.Append(param), Thanks in advance.

Parameter object is improperly defined. Inconsistent or incomplete information was provided

Public Function GetRecordDataSet(ByVal sStoreProcName As String, ByVal sParameterList As String) As ADODB.Recordset
    Try
        Dim cmd As ADODB.Command
        Dim arrParameter, arrParamName
        Dim sParamName As String
        Dim sDataValue
        Dim lCtr As Long
        Dim param As ADODB.Parameter
        GetRecordDataSet = New ADODB.Recordset
        cmd = New ADODB.Command
        cmd.ActiveConnection = con
        cmd.CommandTimeout = 1800
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = sStoreProcName
        If Not Trim(sParameterList) = "" Then
            arrParameter = Split(sParameterList, "|", , vbTextCompare)
            If UBound(arrParameter) >= 0 And IsArray(arrParameter) Then
                For lCtr = 0 To UBound(arrParameter)
                    arrParamName = Split(arrParameter(lCtr), "$", , vbTextCompare)
                    sParamName = arrParamName(0)
                    sDataValue = arrParamName(1)
                    param = cmd.CreateParameter(sParamName, DataTypeEnum.adVarChar,
                                                ParameterDirectionEnum.adParamInput, 200, sDataValue)
                    cmd.Parameters.Append(param) // from this line
                    param.Value = sDataValue
                    GetRecordDataSet = cmd.Execute
                    cmd = Nothing
                    Exit Function
                Next lCtr
            End If
        End If
        GetRecordDataSet = cmd.Execute
        cmd = Nothing
        Exit Function
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Function

UPDATE
I changed my param.Value = sDataValue to param = sDataValue.
The error changed to this:

Unable to cast object of type 'System.String' to type 'ADODB.Parameter'

question from:https://stackoverflow.com/questions/66064013/parameter-object-is-improperly-defined-vb-net-mariadb

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Remove this param = sDataValue from your code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...