[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VB class

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

649 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