?
Solved

VB class

Posted on 2011-03-16
2
Medium Priority
?
284 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

800 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