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

Tech-Archive recommends: Speed Up your PC by fixing your registry



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.

.



Relevant Pages

  • Re: Connecting to an Oracle Database
    ... When I create the command object, ... > connection to it, create the OleDbDataAdapter, bind the command object to ... > close the connection when you fill the data adapter, ... >> Hi Steve, ...
    (microsoft.public.sharepoint.windowsservices)
  • Re: Connecting to an Oracle Database
    ... When I create the command object, ... connection to it, create the OleDbDataAdapter, bind the command object to ... close the connection when you fill the data adapter, ... setup the database connection info ...
    (microsoft.public.sharepoint.windowsservices)
  • Re: File dialog and Data Adapter
    ... the command object has a connection property You can use the file dialog to ... and then build the Connection and command objects. ... > Is it possible pass the file name from a File Dialog to the Data Adapter? ... > need to select an Access database to "open". ...
    (microsoft.public.dotnet.framework.adonet)
  • Strange problem. Need help!
    ... I open a OleDBConnection to the database ... I read the table into a DataSet with the data adapter in step 2. ... Next, in another portion of code, I open a new connection to the same ... I am using a where clause on the command object to only get the ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: why not SQL Authentication?
    ... you're going to have to go to the database to get your data. ... Now what doesn't make sense is for me is to close the command object, ... Why wouldn't I just cache that command object so ... that I could just reuse it again without having to set a connection object ...
    (microsoft.public.dotnet.framework.aspnet.security)