Link to home
Start Free TrialLog in
Avatar of leeds2000
leeds2000Flag for Norway

asked on

How to make this into a function, and then run it in a button

Im noob on functions, and need some help

I need my code to be made into a function, and then i need the ability to call this function inside any buttons i have

the part of the code that will be changed for every button is the "setning" variable
Dim forbindelse As New System.Data.OracleClient.OracleConnection
 
        forbindelse.ConnectionString = "user id=****;password=****;data source=oracle.*******"
        forbindelse.Open()
 
        Dim setning As String = "SELECT querys - changing on every button"
 
 
        Dim kommando As New System.Data.OracleClient.OracleCommand(setning, forbindelse)
 
 
        Dim dataleser As OracleClient.OracleDataReader
        dataleser = kommando.ExecuteReader()
 
        Me.Dgvstatistikk.DataSource = dataleser ''bind the results of the query to the listbox, make sure you have the display and value members of the listbox set to the correct column names in the query
        dataleser.Close()

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ashish Patel
Ashish Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leeds2000

ASKER

Ah, smart ;)

will test is as soon as my database is up and running again :)
SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oki, 2 great suggestions here :), i guess these will work in any way, so i will split the points

Becouse asvforce had a good sub suggestion, and jpaulino had a good function suggestion :)

Thanks guys
thanks leeds2000!