473,320 Members | 1,794 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.

Cannot use "fill" with Datareader

I have an open datareader that gets data from an sql statement, but
when I try to put it into a dataset so that my datagrid can pick it up,
I get a 'System.Data.SqlClient.SqlDataReader' does not contain a
definition for 'Fill' error

// dsRevenue is my datareader object
ds = new DataSet( );
drRevenue.Fill(ds);

Nov 19 '05 #1
5 2056
Right.

The SqlDataReader class doesn't have a Fill method (as the message says).

You are looking for a SqlDataAdapter.

".Net Sports" <ba********@cox.net> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
I have an open datareader that gets data from an sql statement, but
when I try to put it into a dataset so that my datagrid can pick it up,
I get a 'System.Data.SqlClient.SqlDataReader' does not contain a
definition for 'Fill' error

// dsRevenue is my datareader object
ds = new DataSet( );
drRevenue.Fill(ds);

Nov 19 '05 #2
Marina is right here. The SqlDataAdapter takes, at the very least, a
SelectCommand, but also can have Insert, Update and Delete commands.
Have your web page up in VS and go to your toolbox and click the Data
tab. Double click the SqlDataAdapter tool and a wizard will guide you
through creating the data adapter. Then you just do this:

Page_Load(<<args>>)
{
// get data.
daAdapter.Fill(dsDataSet.dtDataTable);

// check for postback.
if (!this.IsPostBack)
{
grdGrid.DataBind();
}
}

Make sure to fill before checking for the postback and only bind when
not a postback. Also, the the Fill method creates a SqlDataReader
behind the scenes and uses it get the data before populating the
datatable with datarows, so it is basically the same thing you were
trying to do.

John

Nov 19 '05 #3
Thanks for the help - . I would have to start this webform over to go
into the VS.net sqldataAdapter wizard to do that. I would just need to
put the data from my DataReader (drRevenue) into a sqlDataAdapter

here's my creation of the datareader

SqlCommand objCommand = new SqlCommand(strSQL, objConn2);
objConn2.Open();

SqlDataReader drRevenue = objCommand.ExecuteReader();

I would now need to do something like:

da = new SqlDataAdapter(drRevenue);

but that is invalid, as SqlDataAdapter wants a command object

Nov 19 '05 #4
On 26 Aug 2005 16:38:28 -0700, ".Net Sports" <ba********@cox.net> wrote:

¤ Thanks for the help - . I would have to start this webform over to go
¤ into the VS.net sqldataAdapter wizard to do that. I would just need to
¤ put the data from my DataReader (drRevenue) into a sqlDataAdapter
¤
¤ here's my creation of the datareader
¤
¤ SqlCommand objCommand = new SqlCommand(strSQL, objConn2);
¤ objConn2.Open();
¤
¤ SqlDataReader drRevenue = objCommand.ExecuteReader();
¤
¤ I would now need to do something like:
¤
¤ da = new SqlDataAdapter(drRevenue);
¤
¤ but that is invalid, as SqlDataAdapter wants a command object

You're still using a DataReader. See the doc for an example of how to use the Fill method with the
DataAdapter:

http://msdn.microsoft.com/library/de...classtopic.asp
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 19 '05 #5
Don't create the datareader. Use the command to create a dataadapter.
The data adapter will create its own data reader behind the scenes
anyway.

John

-----Original Message-----
From: .Net Sports [mailto:ba********@cox.net]
Posted At: Friday, August 26, 2005 4:38 PM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Cannot use "fill" with Datareader
Subject: Re: Cannot use "fill" with Datareader
Thanks for the help - . I would have to start this webform over to go
into the VS.net sqldataAdapter wizard to do that. I would just need to
put the data from my DataReader (drRevenue) into a sqlDataAdapter

here's my creation of the datareader

SqlCommand objCommand = new SqlCommand(strSQL, objConn2);
objConn2.Open();

SqlDataReader drRevenue
= objCommand.ExecuteReader();

I would now need to do something like:

da = new SqlDataAdapter(drRevenue);

but that is invalid, as SqlDataAdapter wants a command object

Nov 19 '05 #6

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

Similar topics

6
by: Fred | last post by:
I have seen this syntax and would like to know weither var_name is entirely filled with zeroes or only a first few bytes are zeroed (for example the first field of the structure). I have of...
4
by: VMI | last post by:
How can I create a comboBox that will display the first item that begins with the group of letters I type? In my current combobox (it's a DropDownList), if I press the letters "S" and "A"...
2
by: Wayne Wengert | last post by:
I am trying to learn to use VS NET and codebehind for asp.net apps and I've run into a problem trying to use a datareader. I created a new webform and inserted and configured a sqlconnection and...
4
by: jojoba | last post by:
hello all, does anyone know if, for a 2-state checkbox, you can use the "fill in" marker from the 3-state checkbox, instead of a checkmark i just like the look of the "fill-in" instead of the...
0
by: Rave | last post by:
This is a long shot, but I thought I'd try it. I am currently using excel as an inventory tool. I currently have a hand-held scanner plugged into a laptop for reading barcodes. Using the "Find and...
0
by: godsmustbcrazy | last post by:
Here is my problem. Brand new SQL Server 2005 Installation 1. Create a database "Test" 2. Create a database user "Domain\user" and set user mapping to "Test" with datareader, datawriter...
3
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I'm trying to add a datagridview control to a Windows Form to display read-only information in visual basic 2005. My understanding is that datareader will be faster for this purpose. I have the...
2
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I have a timout problem when I call "DataAdapter.Fill". When I debug, I see that all timeout settings are correct, ConnectionTimeout is 0 and also CommandTimeout is 0. But when I call...
1
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, how can i fill a consoles background with complete green color? The ForegroundColor member only fills the written buffers background, but i need to fill the complete consoles background...
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...
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: 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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...

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.