Solved

VB class

Posted on 2011-03-16
2
280 Views
Last Modified: 2012-06-22
I am not sure how to create a class to insert data to ms db. I want to create parameters to 10 and then call from my Form1.vb to insert data. PleaseSee my sample below.


vb classe

1. Insert_DB class


public shared sub Insert_data(byval orderdate as string, byval address as string, etc)



...
...
...


mycon.open

mycon.createparameter(10)
mycon.addparameter(0, "@orderdate", orderdate )
etc

and then

mycon.executenonquery("my storeprocedure", commandtype.storedprocedure)



then in my VB form1.vb


call Insert_DB

dim test as new Inset_DB

test.orderdate = "03/16/2011"
test.address = "123 test st...."

at the end then insert data to db
0
Comment
Question by:VBdotnet2005
2 Comments
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 500 total points
ID: 35152085
Hi,

Ok, first of all, in you code example you are declaring your funciton as SHARED (this will mean that you want to call the function without an instance of the class), but you want to use it by making an instance like this

dim test as new Inset_DB

test.orderdate = "03/16/2011"
test.address = "123 test st...."

So, if you want to pass parameter like that, your function should not be shared.

Besides that you can add Properties to your Class, so you can assign the values to them, and your Insert_Data function should not receive any.

Your class would be like the code attached

Hope that helps


Public Class Insert_DB

    Public Property OrderDate() As String
        Get
            Return strOrderDate
        End Get
        Set(ByVal value As String)
            strOrderDate = value
        End Set
    End Property

    Public Property Address() As String
        Get
            Return strAddress
        End Get
        Set(ByVal value As String)
            strAddress = value
        End Set
    End Property

    Public Function Insert_data()

        '...
        mycon.open()

 
        mycon.createparameter(10)
        'Assign the Properties to the Parameters like this
        mycon.addparameter(0, "@orderdate", Me.OrderDate)
        mycon.addparameter(1, "@adress", Me.Address)
        '...

        mycon.executenonquery("my storeprocedure", CommandType.StoredProcedure)


    End Function

End Class

Open in new window

0
 

Author Comment

by:VBdotnet2005
ID: 35158348
Got it to work. Thank you much
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question