469,085 Members | 1,037 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,085 developers. It's quick & easy.

Common procedures for executing all stored procedure

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

Dec 24 '05 #1
1 1318
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
-------------------------
"A1 Ronen" <ro*******@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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

Dec 24 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Eugene Anthony | last post: by
1 post views Thread by Anthony Robinson | last post: by
1 post views Thread by esmith2112 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.