473,320 Members | 2,180 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.

example filling dataset without database

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
4 6173
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Cybertof | last post by:
Hello, Is it necessary to initially fill a dataset to be able to add a new row to the dataset and then update the undercover database ? (In the case of a very large database, this would mean...
2
by: Hugo Lefevre | last post by:
dear, I have a form (frmlogonaccounts.cs) with a combobox, which I want to fill up with the first column of a dataset. The dataset is created in the class Login. My problem is the next : I make...
1
by: Krzysztof Karnicki | last post by:
I have such a problem… I have create my custom DataGridColumn inheriting from System.Windows.Forms.DataGridColumnStyle on using it on DataGrid, to show rows painted by me self. Because dates ...
0
by: AMeador | last post by:
I am new to writing apps that use a database in general and in .NET. I have read about how to use SqlCommands and executing strait SQL for inserts, selects, etc... I have also read about datasets &...
2
by: DC Gringo | last post by:
This code has two SELECT statements, each returning several records. I want to fill a dataset and then two datagrids. How would I fill the SECOND datagrid from this code ----- Sub...
3
by: crjunk | last post by:
I have a 3 table in my DataSet that I'm filling with data. After I've filled these 3 tables, I'm then trying to run a query that will fill a 4th table in the DataSet with data from the three...
4
by: gillcleeren | last post by:
I have a datagrid that has to be filled in a WinForms application. The data comes from an Oracle database. The normal procedure would be filling a dataset, but I have the problem that there are...
11
by: Sid Price | last post by:
I have Dataset that I need to filter into another Dataset for display and I can not find out how to do this. I have found methods for copying a Dataset but I can not see how to filter the rows...
0
by: jaeden99 | last post by:
I have a two drop down list box. The first contains district name(district id is the value) and the the second will contain the user name based on the district selected in the first drop down list....
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...
1
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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

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.