RobinsRL
asked on
SQL data access layer helper class using SqlParameterCollection
I'm trying to create a canned function to handle all non-query, parameterized SQL statements. I've come across the following function, however, I can't seem to use it without receiving errors.
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------
Sub ExecuteNonQuery(ByVal sqlString As String, ByVal sqlParams As SqlParameterCollection, ByVal connectionString As String)
Dim dbCon As New SqlConnection(connectionSt ring)
Dim cmdExp As SqlCommand
cmdExp = New SqlCommand(sqlString, dbCon)
Dim sqlParam As SqlParameter
For Each sqlParam In sqlParams
cmdExp.Parameters.Add(sqlP aram)
Next
dbCon.Open()
cmdExp.ExecuteNonQuery()
dbCon.Close()
End Sub
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
'Code
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim oDA As New Globals.DataAccess.SQL
Dim strSQL As String = "[Some SQL String]"
Dim strConn As String = "[Some Connection String]"
'This is where I'm stuck. I don't know how to add parameters to the collection.
'Dim sqlParams As SqlParameterCollection
oDA.ExecuteNonQuery(strSQL , sqlParams, strConn)
End Sub
--------------------------
Sub ExecuteNonQuery(ByVal sqlString As String, ByVal sqlParams As SqlParameterCollection, ByVal connectionString As String)
Dim dbCon As New SqlConnection(connectionSt
Dim cmdExp As SqlCommand
cmdExp = New SqlCommand(sqlString, dbCon)
Dim sqlParam As SqlParameter
For Each sqlParam In sqlParams
cmdExp.Parameters.Add(sqlP
Next
dbCon.Open()
cmdExp.ExecuteNonQuery()
dbCon.Close()
End Sub
--------------------------
--------------------------
'Code
--------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim oDA As New Globals.DataAccess.SQL
Dim strSQL As String = "[Some SQL String]"
Dim strConn As String = "[Some Connection String]"
'This is where I'm stuck. I don't know how to add parameters to the collection.
'Dim sqlParams As SqlParameterCollection
oDA.ExecuteNonQuery(strSQL
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.add.aspx