473,320 Members | 2,073 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,320 software developers and data experts.

How to use ADO.NET to run a data set returned stored procedure ?

I am going to use ADO.NET to call a sqlserver stored procedure with 1
parameter
The stored procedured will return a record set with one row data.

I have already get connection to the server and added the parameter,
but I cannot get the result by sqldatareader =
sqlcommand.executereader.
I ensure that there is one row return.

Besides, I would like to use the same sqlcommand to run a number of
query in difference function by declaire the variable in global, does
it good idea or I should declaire it in each function?

If it is good to do that, How can I close the sqlcommand and use the
same object in other function just like old ADODB rs.close?

Thank you.

Jul 11 '06 #1
1 1182
Hi

First, try using a DataAdapter instead of a datareader.
Use it to fill a new dataset.
You can use the same command object to create a data adapter.

The data adapter will open and close the connection for you so you
don't need to do this.
If you need to reuse the command, you can probably use the "singleton"
pattern to define a class that can only be instantiated once and
reused. Google for singleton
In your little class, you can have a method that accepts the parameter
and returns a dataset. That method creates your data adapter and fills
the new dataset. As I said above, data adapters will open and close the
connection for you so you don't need to worry about it.

Cylix wrote:
I am going to use ADO.NET to call a sqlserver stored procedure with 1
parameter
The stored procedured will return a record set with one row data.

I have already get connection to the server and added the parameter,
but I cannot get the result by sqldatareader =
sqlcommand.executereader.
I ensure that there is one row return.

Besides, I would like to use the same sqlcommand to run a number of
query in difference function by declaire the variable in global, does
it good idea or I should declaire it in each function?

If it is good to do that, How can I close the sqlcommand and use the
same object in other function just like old ADODB rs.close?

Thank you.
Jul 11 '06 #2

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

Similar topics

2
by: M Wells | last post by:
Hi All, I'm trying to track down a mysterious problem we're experiencing in which updates and inserts to tables in our mssql2k server appear to be 'disappearing.' To explain our situation: ...
2
by: serge | last post by:
My project is to automate testing of Stored Procedures of type SELECT (at least for now). I want to create a table where each stored procedure's input parameter values are entered and in another...
5
by: Raquel | last post by:
This is a very simple DB2 SQLJ stored procedure. The problem is that it seems to run fine but returns NOTHING. I mean..as if nothing has happened..not resultset is returned. I am passing value...
2
by: Josh Strickland | last post by:
I am attempting to create an Access database which uses forms to enter data. The issue I am having is returning the query results from the Stored Procedure back in to the Access Form. ...
2
by: alex.mcshane | last post by:
Hi - I would be grateful for any knowledge regarding the following. Whilst QAing Stored Procedures developed by colleagues, I noticed the following 'superflous' parameter specifications:- 1)...
1
by: Jim Heavey | last post by:
I have a SQL stored procedures which evaluate the values passed in parameters and then based on those values reads the appropriate records. I run the stored procedure in VS 2005 Debug mode and it...
1
by: satish mullapudi | last post by:
Hi, I am using DB2 v8.2 & jdk 1.4. 1. I have a java program which returns an array which contains 1 to 5 numbers. The code: public class ArrayTest { public static final int ARRAY_SIZE = 5;...
0
by: aarnan | last post by:
I have two SqlDataSources that use two different stored procedures that take parameters to populate two controls, one dependant on an element of the other. The first data source,...
5
by: acx | last post by:
Dear Group, I have got some XML code which I need to send from my SQL Server database to some remote application server via POST method. The application server will return XML code as well and...
1
by: CSINVA | last post by:
I have a stored procedure that returns columns from a table called UserProfile. Within the table, it has a column called ProfielD, PropertyValue, Visitbility. I need to be able set the values...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.