Solved

VB class

Posted on 2011-03-16
2
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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