473,566 Members | 3,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Importing CSV to Dataset Problem

Hi everyone
Can anybody please help me? I am trying to write my first project in ASP.
NET (C#) and I am having some issues trying import a CSV file to populate
the form with values

I have a basic CSV file (bookName, bookPrice) and on the PageLoad event I
perform the method as below (!=postback of course)

private void LoadBooks ()
{
string delimiter = ",";
string tableName = "BooksTable ";
string fileName = Server.MapPath( "/DepartmentStore/data" + "/books.txt");

DataSet dataset = new DataSet();
StreamReader sr = new StreamReader(fi leName);

dataset.Tables. Add(tableName);
dataset.Tables[tableName].Columns.Add("p roduct");
dataset.Tables[tableName].Columns.Add("p rice");

string allData = sr.ReadToEnd();
string[] rows = allData.Split(" \r\n".ToCharArr ay());

foreach(string r in rows)
{
string[] items = r.Split(delimit er.ToCharArray( ));
dataset.Tables[tableName].Rows.Add(items );
}
}

What I would like to do is now populate the form from the values that have
been imported into the datatable however, I am not sure how to call it. In
the same method, I would like to have something that says lblBook1.Text =
item[0] or something like that. (I have a CSV file with 6 books in it) Not
sure if I am on the right track. From what I understand, I have created a
dataset, added a table with two colums, read the entire text file, and split
the row at the delimiter.

Sorry for the newbie question, but any help would be very appreciated.

Greg :-)


Nov 17 '05 #1
1 9327
You can attach the DataSet directly with a DataGrid object to render on your
ASP.NET app or you can access each of the rows yourself and render them like
this:

string col1="";
string col2="";
for(i = 0; i < dataset.Tables[tablename].Rows.Count) {
col1 = dataset.Tables[tablename].Rows[i][0]; // row i column 0
col2 = dataset.Tables[tablename].Rows[i][1]; // row i column 1
}
"Gregory Pearce" <PL************ **********@PLEA SEREMOVEyahoo.c om.au> wrote
in message news:qv******** ***********@new s-server.bigpond. net.au...
Hi everyone
Can anybody please help me? I am trying to write my first project in ASP.
NET (C#) and I am having some issues trying import a CSV file to populate
the form with values

I have a basic CSV file (bookName, bookPrice) and on the PageLoad event I
perform the method as below (!=postback of course)

private void LoadBooks ()
{
string delimiter = ",";
string tableName = "BooksTable ";
string fileName = Server.MapPath( "/DepartmentStore/data" +
"/books.txt");

DataSet dataset = new DataSet();
StreamReader sr = new StreamReader(fi leName);

dataset.Tables. Add(tableName);
dataset.Tables[tableName].Columns.Add("p roduct");
dataset.Tables[tableName].Columns.Add("p rice");

string allData = sr.ReadToEnd();
string[] rows = allData.Split(" \r\n".ToCharArr ay());

foreach(string r in rows)
{
string[] items = r.Split(delimit er.ToCharArray( ));
dataset.Tables[tableName].Rows.Add(items );
}
}

What I would like to do is now populate the form from the values that have
been imported into the datatable however, I am not sure how to call it. In
the same method, I would like to have something that says lblBook1.Text =
item[0] or something like that. (I have a CSV file with 6 books in it) Not
sure if I am on the right track. From what I understand, I have created a
dataset, added a table with two colums, read the entire text file, and
split
the row at the delimiter.

Sorry for the newbie question, but any help would be very appreciated.

Greg :-)

Nov 17 '05 #2

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

Similar topics

2
2018
by: Lee Ottaway | last post by:
In order to achieve the archiving of old data from my database I have exported the information from my dataset to an XML file using the standard WriteXML method of the object. Now suppose in the future I wish to restore only specific records (which all have a unique reference) from that file back to the dataset so they can be restored back...
5
1565
by: Alex | last post by:
Hi, I have an aspx file that creates a custom class object and calls a method which should return a DataSet. It throws a: Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's...
0
1688
by: optimizeit | last post by:
What I am attempting to do is import an Excel Workbook and display the worksheets in a datagrid dynamically. I am very close to getting this to work. I have to this point successfully imported a single worksheet into a dataset. I successfully built a dynamic datagrid. And I did successfully bind it to the dataset. Then I added the datagrid...
0
1035
by: Gregory Pearce | last post by:
Hi everyone Can anybody please help me? I am trying to write my first project in ASP. NET (C#) and I am having some issues trying import a CSV file to populate the form with values I have a basic CSV file (bookName, bookPrice) and on the PageLoad event I perform the method as below (!=postback of course) private void LoadBooks () {
0
1504
by: Mike Collins | last post by:
I am trying to export data from multiple tables in SQL Server to an XML file so I can then import it to another database. It seems to be working fine for exporting, but I am having trouble importing the file. Can someone show me where I am going wrong. Even though I say the export is working, I am including it below in case there is something...
5
2163
by: Mike Collins | last post by:
I am trying to export data from multiple tables in SQL Server to an XML file so I can then import it to another database. It seems to be working fine for exporting, but I am having trouble importing the file. I am getting the following error trying to import the same xml file I just exported. "System.Data.SqlClient.SqlException: Line 1:...
0
1475
by: Mike Collins | last post by:
I am importing a XML file and have not been having the best of luck in doing this, but I do have the following solution below. I will not be importing more than 2000 records at a time, but will be importing data to many different tables. Can someone explain if there is a better way to do what I am doing without having to call a stored...
2
2105
by: Mike Collins | last post by:
I am importing a XML file and have not been having the best of luck in doing this, but I do have the following solution below. I will not be importing more than 2000 records at a time, but will be importing data to many different tables. Can someone explain if there is a better way to do what I am doing without having to call a stored...
12
6193
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the datagrid. Once I can get to that point I need some way to be able to add new data only to the new columns that were added. Here is some of my...
0
7673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8109
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7645
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.