473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

SQL to resultset

Hi

I have an sql statement in a string variable SQLStr and I also have an
oledbconnection Conn with my database. What can I do from here to run the
sql and get a handle to the resultset in my app? I want to be able to go
through the records in the resultset in a loop and read the field values.

Thanks

Regards
Jan 10 '08 #1
3 4012
"John" <Jo**@nospam.infovis.co.ukschrieb
Hi Armin

Many thanks. Is it possible to also assign this datareader resultset
to a gridview control?
I don't know. Probably not because it must have access to all the data
at any time. The DataReader is forward-only and provides access to the
current record only
if not, is there another way?
Yes, the 2nd link.
Armin
Jan 10 '08 #2
John,

These newsgroups aren't meant for teaching - instead they are for solving
problems.
IMO you should know the basics at least for your own good and for not asking
really basic questions.
Note that this is my opinion and I am not forcing you to anything.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"John" <Jo**@nospam.infovis.co.ukwrote in message
news:el**************@TK2MSFTNGP03.phx.gbl...
Miha, teaching doesn't help the student alone, it helps the teacher as
well. All good teachers know that.
Jan 11 '08 #3
John, as most mentioned here, it would be beneficial to go through
some basic ADO.Net material, this stuff should come to you pretty
quickly.

But in the meantime, here's the basic method to get a dataset filled
with your sql query (and for the experts, please feel free to chime in
with corrections, I can certainly use the input as well):

The following is with System.Data.SqlClient imported:

Imports System.Data.SqlClient << this goes before the class
declaration.

Dim conn1 As New
SqlConnection("server='serverAddr';uid='userId';pw d='yurPass';database=somethingName;")
Dim sqlString As String = "select * from zipCode"
Dim adapter1 As New SqlDataAdapter(sqlString, conn1)
Dim ds1 As New Data.DataSet

adapter1.Fill(ds1)
adapter1.Dispose()

MsgBox(ds1.Tables(0).Rows(0).Item(1))

You'll be able to access the tables, rows and columns of your result
off the dataset.

Also, if you're looking to loop through your result you can get a
count of the number of rows by:

ds1.Tables(0).Rows.Count

This is what I use, it's by no means the only or the best way of
retrieving data, but seems to work ok.

- Joe

On Jan 9, 6:50*pm, "John" <J...@nospam.infovis.co.ukwrote:
Hi

I have an sql statement in a string variable SQLStr and I also have an
oledbconnection Conn with my database. What can I do from here to run the
sql and get a handle to the resultset in my app? I want to be able to go
through the records in the resultset in a loop and read the field values.

Thanks

Regards
Jan 11 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: RoyalScorpion | last post by:
hi guys, i get an updatable resultset from a connection then used it to insert a new row but the result set doesn't chane after insertion, i mean the no of rows before insertion is the same after...
1
by: Harrie K. | last post by:
I want to make an Stored Procedure on a Oracle 7.x database that fills a resulset based on the values in an array: CREATE OR REPLACE PACKAGE PCK_SET IS TYPE rec_set IS RECORD ( type_id NUMBER...
2
by: Savas Ates | last post by:
I have a stored procedure below.. When I run it with a well parameter in query analyser 3 of select statements return me. (i named select statements 1,2,3) But in asp page when i call this...
7
by: Gandalf | last post by:
Hi all, I am connecting to DB2 8.1 on Solaris through JDBC type 4 drivers (driver: com.ibm.db2.jcc.DB2Driver). Problem is that when a cursored query is done, the resultset gets closed after...
2
by: Twan Kennis | last post by:
Question: How do I pass a returning resultset from a nested Stored Procedure (which opens a cursor including option "WITH RETURN TO CALLER") as a returning resultset from it's own? When I...
4
by: _link98 | last post by:
Problem: java ResultSet cursor from SQL/PL stored-procedure is FORWARD_ONLY. Is it possible to have ResultSet cursors from SQL/PL procedures to scroll forward and backwards? Perhaps I am missing...
12
by: robertino | last post by:
Hi all, I've put together a few SPs to produce a BOM (bill of materials) listing, which together use a couple of global temp tables, and return the results from a cursor. Here's the code: ...
0
by: David Linsin | last post by:
I created a simple test case to reproduce the problem (also check Bug #15500): import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement;...
13
by: ajos | last post by:
hi frnds, im doing some db related operations in my web project,im using mysql 5.0,i have the following piece of code in my action class- for(resultset =...
5
by: lost1 | last post by:
I am having trouble adding a result set to a scroll pane. no matter what I do using getText I get an error. Can someon give me a clue? import java.util.*; import java.sql.*; import java.awt.*;...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.