473,387 Members | 3,821 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,387 software developers and data experts.

import file in dataset problem

Hi

I try to import file in a dataset. How I can do this ?
Jul 21 '05 #1
2 3444
Hi ERic,
Hi

I try to import file in a dataset. How I can do this ?


First you need a DataTable to put the stuff in. If you want to import a
CSV-file, you can separate the different items using the
String.Split()-method. For example (from scratch):
===============================
// Create dynamic Table
DataTable dt = new DataTable();

// Create Row Data - in this case 3 columns which means
// That in your CSV-file are also only 3 items per row
dt.Columns.Add("ComputerID", System.Type.GetType("System.String"));
dt.Columns.Add("Computername", System.Type.GetType("System.String"));
dt.Columns.Add("Active", System.Type.GetType("System.String"));

// Read the Textfile
StreamReader sr = new StreamReader(yourfilename);

string datStr;
do {
datStr = sr.ReadLine();
if ( datStr != null ) {
string[] rowData = sr.Split(',');

// CreateRow
DataRow dr = dt.NewRow();
// Fill Row
dr["ComputerID"] = rowData[0];
dr["Computername"] = rowData[1];
dr["Active"] = rowData[2];
// Add Row
dt.Rows.Add( dr );
}
} while ( datStr != null );

DataSet ds = new DataSet();
// Insert Table
ds.Tables.Add( dt );

===============================

Remember, this is not proved, I just wrote it down from scratch ... but this
is the way to go, I suppose.

Regards,

--
Frank Eller [.NET MVP]
www.frankeller.de
..NET Developers Group Munich- www.munichdot.net
Jul 21 '05 #2
see my other reply to your similar query in this same newsgroup.

"Eric Caron" <ec****@pgsystem.com> wrote in message
news:av********************************@4ax.com...
Hi

I try to import file in a dataset. How I can do this ?

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ed Bacon | last post by:
I am trying to produce a generic "audit report" for various transactions in our application. Each transaction type defines a document (and has an associated schema). When a transaction leads to a...
2
by: Ghost | last post by:
Hello. What is the optimal way to manualy import/export data from/to XML file to/form my DataSet? What I wnat: 1. To add some data (records) from XML file to may dataset. 2.. To add some...
3
by: Schultz | last post by:
I would like to know if it is possible to import data from MS Excel 2000 to a dataset using asp.net. The excel file would need to be uploaded to the server from a web page first, before the loaded...
0
by: Locusta | last post by:
Hello, I'm looking for a generic way to import XML documents into a local SQLCE database (on Pocket PC). To complicate, the local SQLCE database has more fields in the tables than the XML...
7
by: Joe Fallon | last post by:
I am importing a delimited ASCII text file into a dataset using OLEDB. I set up the connection and dataadapter and then fill the dataset. It works - sort of. It turns out that some of my data is...
2
by: Eric Caron | last post by:
Hi I try to import file in a dataset. How I can do this ?
4
by: BostonNole | last post by:
I am looking for suggestions on the most efficient way to import 7 different fixed width files into a DataSet. Not all at the same time. One file at a time, but the format could change from file...
1
by: The_Fakir_42 | last post by:
Hi, I have a very tricky problem... I import an XLS file from my asp web application; this xls file contains lots of single-cell named areas. Usually, I know how to get them, this way : '...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.