By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,763 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,763 IT Pros & Developers. It's quick & easy.

example filling dataset without database

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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];
}

Nov 17 '05 #2

P: n/a
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" wrote:
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];
}

Nov 17 '05 #3

P: n/a
I found the answer myself...

"rd.SetDataSource(ds);"

works fine ;)

Thx for help, Ashura

Best regards

Fabian

"Fabian" wrote:
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" wrote:
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];
}

Nov 17 '05 #4

P: n/a
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)
Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.