473,413 Members | 1,799 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,413 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 3445
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.