example filling dataset without database

G

Guest

Hello,

i need an example to fill a Dataset Object without a Database.
I want to save Strings, like a Database for using it in a Crystal Report.

Does anyone have an example for me please ?

Thx and regards

Fabian
 
G

Guest

heres a simple 1

void InitializeDataGrid() {
DataSet ds = new DataSet("DataSet");
DataTable data = new DataTable("Data");
DataColumn dtCol = null;

dtCol = new DataColumn("ID");
dtCol.DataType = typeof(System.Int32);
data.Columns.Add(dtCol);

dtCol = new DataColumn("Name");
dtCol.DataType = typeof(System.String);
data.Columns.Add(dtCol);

DataRow dr = null;
for(int i = 0; i < 10; i++) {
dr = data.NewRow();
dr["ID"] = i;
dr["Name"] = "Name[" + i + "]";
data.Rows.Add(dr);
}

ds.Tables.Add(data);
grdData.DataSource = ds.Tables[0];
}
 
G

Guest

Hi,

thx for the answer, i think this is what i was searching for.
But i cant test it, because i want to give this data to a Crystal Report,
and if i say

"
ReportDocument rd = new ReportDocument();
rd.Load("F:\\crRechnung.rpt");
rd.Database.Tables[0].SetDataSource(ds.Tables[0]);
//rd.Database.Tables[0].SetDataSource(ds); //doesnt work too
crystalReportViewer.ReportSource = rd;
"
I get the answer that the Table index of my rd.Database is not valid. But i
cant find any function to add a new table in there. Do you know that problem
too and give me a help ?

Thx and regards

Fabian
 
G

Guest

I found the answer myself...

"rd.SetDataSource(ds);"

works fine ;)

Thx for help, Ashura

Best regards

Fabian



Fabian said:
Hi,

thx for the answer, i think this is what i was searching for.
But i cant test it, because i want to give this data to a Crystal Report,
and if i say

"
ReportDocument rd = new ReportDocument();
rd.Load("F:\\crRechnung.rpt");
rd.Database.Tables[0].SetDataSource(ds.Tables[0]);
//rd.Database.Tables[0].SetDataSource(ds); //doesnt work too
crystalReportViewer.ReportSource = rd;
"
I get the answer that the Table index of my rd.Database is not valid. But i
cant find any function to add a new table in there. Do you know that problem
too and give me a help ?

Thx and regards

Fabian


Ashura said:
heres a simple 1

void InitializeDataGrid() {
DataSet ds = new DataSet("DataSet");
DataTable data = new DataTable("Data");
DataColumn dtCol = null;

dtCol = new DataColumn("ID");
dtCol.DataType = typeof(System.Int32);
data.Columns.Add(dtCol);

dtCol = new DataColumn("Name");
dtCol.DataType = typeof(System.String);
data.Columns.Add(dtCol);

DataRow dr = null;
for(int i = 0; i < 10; i++) {
dr = data.NewRow();
dr["ID"] = i;
dr["Name"] = "Name[" + i + "]";
data.Rows.Add(dr);
}

ds.Tables.Add(data);
grdData.DataSource = ds.Tables[0];
}
 
G

Guest

my guess is that the dataset dose NOT contain the tables that the crystal
report expected.

plz check the code i cpy'ed across for adding yet another datatable

DataSet ds = new DataSet("DataSet");
DataTable data = new DataTable("Data");

ds.Tables.Add(data);

BTW: there shud be some relationship among those tables in the set which
needs to be added as well (prolly this is why the crystal report complainning)
 

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