Link to home
Start Free TrialLog in
Avatar of RobinsRL
RobinsRLFlag for United States of America

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(connectionString)

            Dim cmdExp As SqlCommand
            cmdExp = New SqlCommand(sqlString, dbCon)

            Dim sqlParam As SqlParameter
            For Each sqlParam In sqlParams
                cmdExp.Parameters.Add(sqlParam)
            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



ASKER CERTIFIED SOLUTION
Avatar of Sammy
Sammy
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial