Solved

Writing a SQL query through VB.net to oracle

Posted on 2007-11-19
4
163 Views
Last Modified: 2010-05-19
Hey, i need to connect to oracle when i press a button, and ask this SQL query:

SELECT oi.vare_nr, oi.ans_nr, COUNT(*)
FROM ordreinfo oi, vare v, ansatt a
WHERE v.vare_nr = oi.vare_nr
AND a.ans_nr = oi.ans_nr
GROUP BY oi.vare_nr, oi.ans_nr;

after this i need to get the information i receive from the SQL query to a listbox, how do i do this?


I was thinking something like this (its some variables there in norwegian, but you understand :))

I dont understand how i should implement this SQL query to my code, and i dont know if this is the correct way to go :)
Dim forbindelse As New System.Data.OracleClient.OracleConnection
 

        forbindelse.ConnectionString = "user id=****;password=****;data source=oracle.*******"

        forbindelse.Open()
 

        Dim setning As String = "sql query?????"
 
 

        Dim kommando As New System.Data.OracleClient.OracleCommand(setning, forbindelse)
 
 

        Dim dataleser As OracleClient.OracleDataReader

        dataleser = kommando.ExecuteReader()

Open in new window

0
Comment
Question by:leeds2000
  • 2
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
Solar_Flare earned 500 total points
ID: 20316928
yes you are on the right track

once that code has finished you will want to set the datasource of the listbox = dataleser
Dim forbindelse As New System.Data.OracleClient.OracleConnection

 

        forbindelse.ConnectionString = "user id=****;password=****;data source=oracle.*******"

        forbindelse.Open()

 

        Dim setning As String = "SELECT ...."

 

 

        Dim kommando As New System.Data.OracleClient.OracleCommand(setning, forbindelse)

 

 

        Dim dataleser As OracleClient.OracleDataReader

        dataleser = kommando.ExecuteReader()
 

 listbox1.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

0
 
LVL 3

Author Comment

by:leeds2000
ID: 20316979
Okei, i will try this tomorrow, thanks for the help so far :)
0
 
LVL 3

Author Comment

by:leeds2000
ID: 20329955
Im struggling with getting the information from this SQL query to show in the listbox or a datagridview, how do i do this?
please help
0
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 20378323
you need to make sure the datatextfield and datavaluefield are set to the appropriate field names from the query so it knows which fields to use for the text and value
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
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…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

864 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

20 Experts available now in Live!

Get 1:1 Help Now