'the function
Public Shared Function InsertNewRecord(ByVal myStoredProcedure As String) As Boolean

    Dim conn As New SqlConnection
    conn = MyFormz.connec.ConnWeb2()
    Dim cmdInsert As New SqlCommand
    Dim sSQL As New String("")
    Dim iSqlStatus As Integer
    sSQL = myStoredProcedure
      With cmdInsert
        .CommandText = sSQL 'Your sql statement
        .CommandType = CommandType.StoredProcedure
        '.Parameters.AddWithValue("@value1", item1)
        '.Parameters.AddWithValue("@value2", item2)
        '.Parameters.AddWithValue("@value3", item3)
        'Set the connection of the object
        .Connection = conn
      End With
      'Set the iSqlStatus to the ExecuteNonQuery 
      'status of the insert (0 = success, 1 = failed)
      iSqlStatus = cmdInsert.ExecuteNonQuery
      If Not iSqlStatus = 0 Then
        Return False
        Return True
      End If
    Catch ex As Exception
    End Try
  End Function
'the code to call the function
Dim obj As ClassClass = New ClassClass
    'obj.InsertNewRecord = New 
    obj.InsertNewRecord = New inse

i have a function that i have in my data access class now i want to access it then declare and assign parameters and then insert data into database can someone help.any help would be appreciated

Recommended Answers

All 3 Replies

'in another form


Thanx man for your reply.I think i need to explain myself a little bit more, is i have a function that i made to insert new records into a database. this function is in my data access class. and i want to now access it in another form, put in the argument which is the stored procedure. and also SET the PARAMETERS for that stored procedure as you can see from the function i originally sent i commented out the part where i was supposed to put parameters, so that i can access the function in different places set the argument put in the parameters and insert. Is what i'm trying to do possible in the first place.what is the best way to go about this?

sorry.. i'm forgot to reply.

first, u dont have to use Shared function.

just make it as public : Public Function InsertNewRecord(ByVal myStoredProcedure As String) As Boolean then declare a new variable as your class instance..
ex : Dim Stuff as New DataAccess example when call at any event :

if Stuff.InsertNewRecord(ParameterHere) = True then
   msgbox "Data Added!"
end if

just it..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.