Re: stored procedure results

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: John M Deal (johndeal_at_necessitysoftware.com)
Date: 11/19/04


Date: Thu, 18 Nov 2004 20:07:14 -0800

What you are doing will be problematical at best. First there is the
issue that each sResults statement is overwriting the previous contents.
  Now if you want to display things in a datagrid, you could first
rethink the use of a datareader and fill a dataset instead. The
datareader is a one way optimized for reading object so you won't be
able to directly bind it to a datagrid, however if you retrieve your
results to a data grid you can bind it. Finally if you are stuck on
using a datareader then I'd recommend checking out this article showing
how to convert a datareader to a dataset:

http://authors.aspalliance.com/stevesmith/articles/convertReadertoSet.asp

If you follow the article you should be able to bind the resulting
dataset (or more specifically the created table) to the datagrid (from
you method you'd want to return the dataset). Oh, you didn't mention
what type of app you need this for, but it should work equally well for
ASP.Net and winforms. Hope this helps.

Have A Better One!

John M Deal, MCP
Necessity Software

jaYPee wrote:
> I have downloaded some source code but I want this to convert the
> results into datagrid.
>
> dr = cmd.ExecuteReader()
>
> '****************************************
> ' SHOW THE RESULTS
> '****************************************
>
> sResults = "CustomerID" + vbTab + "ContactName" + vbTab +
> vbTab + "CompanyName" + vbCrLf + vbCrLf
>
> While dr.Read()
>
> sResults = sResults + dr.Item("CustomerID") + vbTab +
> vbTab
> sResults = sResults + dr.Item("ContactName") + vbTab +
> vbTab
> sResults = sResults + dr.Item("CompanyName") + vbCrLf
>
> End While
>
> dr.Close()
>
> Return sResults
>
> Anyone know how can I put the results into datagrid?
>
> thanks in advance.



Relevant Pages

  • Re: stored procedure results
    ... Now if you want to display things in a datagrid, ... rethink the use of a datareader and fill a dataset instead. ... results to a data grid you can bind it. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Datareader, Datagrid and hyperlinks
    ... >as listed in my last response, but instead of the hyperlink column, use the ... >>I am filling a datareader and then assigning the reader to the datagrid as ... I can do this when binding the ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Datareader, Datagrid and hyperlinks
    ... >as listed in my last response, but instead of the hyperlink column, use the ... >>I am filling a datareader and then assigning the reader to the datagrid as ... I can do this when binding the ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)
  • Number of records in DataReader
    ... I want to check whether my datareader object contains rows before continuing ... and binding it to my ASP datagrid. ... rows with SQL function count, followed by the same query to retrieve the ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: which is a better use of the data
    ... Isn't disconnecting it by using a datatable good for changing more than one ... With a DataReader you can dump to the datagrid and when you perform ... then use DataReader to get data and drop it onto a DataGrid ... And that datatables are disconnected and ...
    (microsoft.public.dotnet.framework.adonet)