Solved

VB class

Posted on 2011-03-16
2
278 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now