Common procedures for executing all stored procedure

A

A1 Ronen

Hi all
I got problem regarding executing all stored procedure through
common procedures where we have different parameter with different
names, type and data type


The Function is as follows

Where strProcString is procedure name and strParamString is all
parameters concatenated by @

Public Function CeateDataSetSQL(ByVal strProcString As String, ByVal
ByVal strParamString As String) As DataSet
Dim dsLIS As DataSet
Dim Varr As System.Array
Dim Varr2 As System.Array
Dim intNoOfParameters As Integer
Dim j As Integer
If Not IsConnectionOpen Then
RaiseEvent ConnectionStatus("Connecting to SQL Server")
End If
Try

Dim conDatabase As New SqlConnection(strConnection)
Dim cmdCommand As New SqlCommand(strProcString,
conDatabase)
cmdCommand.CommandType = CommandType.StoredProcedure

dsLIS = New DataSet
sdaLISAdapter = New SqlDataAdapter(cmdCommand)
Varr = Split(strParamString, "@")
intNoOfParameters = UBound(Varr)

For j = 1 To intNoOfParameters
cmdCommand.Parameters.Add(New SqlParameter).Value =
CType(Varr.GetValue(j), String)
Next j



Me.sdaLISAdapter.Fill(dsLIS, "Result")


Catch ex As Exception

MsgBox(Err.Number & vbNewLine & Err.Description)

End Try

Return dsLIS

End Function

Where BOLD code give Error as parameter1 not present in given stored
procedure
 
K

Ken Tucker [MVP]

Hi,

When you add a parameter to a sqlcommand you need to provide the
parameter name and value.

cmdHit.Parameters.Add("@Id", strId) ' use addwithvalue for vs 2005

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top