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

import file in dataset problem

P: n/a

I try to import file in a dataset. How I can do this ?
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
Hi ERic,

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.


Frank Eller [.NET MVP]
..NET Developers Group Munich-
Jul 21 '05 #2

P: n/a
see my other reply to your similar query in this same newsgroup.

"Eric Caron" <ec****> wrote in message

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

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.