populating a DataTable in a DataSet

  • Thread starter Wilfried Mestdagh
  • Start date
W

Wilfried Mestdagh

Hi,

I have done following: Add new item - Dataset, then add DataTable, and
add a few fields (VS2005) because this seems the only way to let a
Crystalreport recognize a datatable in the project.

Now the problem, should be simple but I cannot find it. How can I
populate the dataTable in code ? I don't need a connection to a
database and so.
 
D

Dave Sexton

Hi Wilfried,

I'm sorry, I just realized you wrote "don't" need a connection to a database.

In that case, here's a simple example. Assuming that you have a strong-typed
DataSet named, "PeopleData" that contains a single DataTable named, "People",
which only contains a single column named, "Name" of type System.String, you
could do the following:

PeopleData data = new PeopleData();
data.People.AddPeopleRow("Joe");
data.People.AddPeopleRow("Fred");
data.AcceptChanges();

HTH
 
B

Brendon Bezuidenhout

Heya Wilfried,

Daft question - but re your Crystal Report - Are you attempting to
dynamically alter the design and such of the CrystalReport proper? If so a
heads up of a headache that I had to find out the hard way - You can't with
the API and CrystalReports namespace that is shipped with VS2005...

If not ignore me :)

Brendon
 
W

Wilfried Mestdagh

Hy Brendon,

Yes and no, but I just discovered ReportViewer witch seems very much
simpler to work with. Also it understand Object Data Sources, which I
think this is improvement. Now I have to learn these things too :)

--
rgds, Wilfried [MapPoint MVP]
http://www.mestdagh.biz

Brendon said:
Heya Wilfried,

Daft question - but re your Crystal Report - Are you attempting to
dynamically alter the design and such of the CrystalReport proper? If so
a heads up of a headache that I had to find out the hard way - You can't
with the API and CrystalReports namespace that is shipped with VS2005...

If not ignore me :)

Brendon
 
G

Guest

Here is an alternate way (not using strongly typed):

DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("TEST");
DataRow row ;
for(int i = 0;i<3;i++)
{
row=dt.NewRow();
row["TEST"] ="Howdy " +i.ToString();
dt.Rows.Add(row);
}
ds.Tables.Add(dt);

Done! Cheers,

Peter
 

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