How can i use a dataset w/o a datasource?

F

forest demon

what i'm trying to do is attach a report file to a reportviewer
instance with some values from a page. i can attach a dataset to
the .rdlc file with stuff from a datasource, but i need to also add
values form a pages web controls to the same report.

it was recommended, on here, that i create a dataset in memory and add
that to the report. i'm not sure how to do that at this point without
a datasource. i'm drawing a blank.

thanks to all who reply....

-
fd
 
A

Alberto Poblacion

forest demon said:
what i'm trying to do is attach a report file to a reportviewer
instance with some values from a page. i can attach a dataset to
the .rdlc file with stuff from a datasource, but i need to also add
values form a pages web controls to the same report.

it was recommended, on here, that i create a dataset in memory and add
that to the report. i'm not sure how to do that at this point without
a datasource. i'm drawing a blank.

Simply build the dataset step by step by adding to its collections in
your code:

DataSet ds = new DataSet();
DataTable dt = new DataTable("name");
ds.Tables.Add(dt);
dt.Columns.Add("Col1", typeof(string));
dt.Columns.Add("Col2", typeof(int));
dt.Rows.Add(new object[]{"value1", 123});
dt.Rows.Add(new object[]{"value2", 456});
//Now ds is a dataset that contains one table with two columns and two rows
 
F

forest demon

what i'm trying to do is attach a report file to a reportviewer
instance with some values from a page. i can attach a dataset to
the .rdlc file with stuff from a datasource, but i need to also add
values form a pages web controls to the same report.
it was recommended, on here, that i create a dataset in memory and add
that to the report.  i'm not sure how to do that at this point without
a datasource.  i'm drawing a blank.

    Simply build the dataset step by step by adding to its collectionsin
your code:

DataSet ds = new DataSet();
DataTable dt = new DataTable("name");
ds.Tables.Add(dt);
dt.Columns.Add("Col1", typeof(string));
dt.Columns.Add("Col2", typeof(int));
dt.Rows.Add(new object[]{"value1", 123});
dt.Rows.Add(new object[]{"value2", 456});
//Now ds is a dataset that contains one table with two columns and two rows

thanks for the input. i'm able to make this work now....
 
F

forest demon

what i'm trying to do is attach a report file to a reportviewer
instance with some values from a page. i can attach a dataset to
the .rdlc file with stuff from a datasource, but i need to also add
values form a pages web controls to the same report.
it was recommended, on here, that i create a dataset in memory and add
that to the report.  i'm not sure how to do that at this point without
a datasource.  i'm drawing a blank.

    Simply build the dataset step by step by adding to its collectionsin
your code:

DataSet ds = new DataSet();
DataTable dt = new DataTable("name");
ds.Tables.Add(dt);
dt.Columns.Add("Col1", typeof(string));
dt.Columns.Add("Col2", typeof(int));
dt.Rows.Add(new object[]{"value1", 123});
dt.Rows.Add(new object[]{"value2", 456});
//Now ds is a dataset that contains one table with two columns and two rows

should i cast the value prior to adding it to the row?
if not, i get the DataRow type when trying to use the text value in
the array.

thanks...
 
F

forest demon

    Simply build the dataset step by step by adding to its collections in
your code:
DataSet ds = new DataSet();
DataTable dt = new DataTable("name");
ds.Tables.Add(dt);
dt.Columns.Add("Col1", typeof(string));
dt.Columns.Add("Col2", typeof(int));
dt.Rows.Add(new object[]{"value1", 123});
dt.Rows.Add(new object[]{"value2", 456});
//Now ds is a dataset that contains one table with two columns and two rows

should i cast the value prior to adding it to the row?
if not, i get the DataRow type when trying to use the text value in
the array.

thanks...- Hide quoted text -

- Show quoted text -

oh geesh...nevermind. i figured it out. sorry....

thanks again for your help. i do appreciate it.

-
fd
 
S

sloan

You can also create a (strongly typed) dataset. And get strong typing.

Start a new Console Application:

Add / New Item / DataSet.

Call it "EmployeeDS". (or EmployeeDS.xsd)

Right click (in the design area) ... Add a table. "Employee"

Add 3 columns

ID (int)
LastName (string)
FirstName (string)


...
then you can "code up" a version like this

EmployeeDS ds = new EmployeeDS();

//first way
ds.Employee.AddNewEmployeeRow ( 123, "Smith" , "John");
//second way
EmployeeDS.Employee.EmployeeRow newRow = ds.Employee.NewEmployeeRow();
newRow.ID = 234;
newRow.LastName = "Jones";
newRow.FirstName = "Mary";

ds.Employee.AddNewEmployeeRow ( newRow ) ;

string x = ds.GetXml();


I do that all the time for UnitTests, and testing code without talking to
the database.

Good luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top