Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 669
  • Last Modified:

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



0
RobinsRL
Asked:
RobinsRL
1 Solution
 
SammyCommented:
You need an SQLCommand to add the parameters to
Dim objSqlCommand as SqlCommand=New SqlCommand
With ObjSqlCommand
.Parameters.Add("@SomeParam", SqlDbType.Int).Value = 0
End With

If you are using asp.net 2.0 you have to use
AddWithValue("@SomeParam", object Value)

Good luck
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now