Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Read .CSV file

Posted on 2003-10-28
2
Medium Priority
?
2,445 Views
Last Modified: 2009-12-16
Hi,

I was wondering if anyone could help me.

i have a csv file which is located locally at c:\INPUT.CSV

i am trying to read this file into a Datagrid but with out success.

i can do it if it was a Access database using something like

System.Data.OleDb.OleDbConnection conn = new
System.Data.OleDb.OleDbConnection();
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\\WSFEEDBACK.mdb");
                                    
aConnection.Open();      
OleDbCommand aCommand = new OleDbCommand("SELECT * FROM WebEvents ",aConnection);
DataSet DS = new DataSet();
                                          
try
{
OleDbDataAdapter myDA = new OleDbDataAdapter(aCommand);      
myDA.Fill(DS);
OleDbDataReader myDataReader = aCommand.ExecuteReader();
                        
 if( myDataReader.Read() )
      {
And so on..............................

Bit HOW do i fill a Dataset if it was a CSV file?

any help will be much appreciated..

Thanks.

wazzajs

0
Comment
Question by:wazzajs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
tgannetts earned 760 total points
ID: 9641408
I use the following to create a dataset from a csv:
(using your 'c:\Input.csv' as example)

using System;
using System.Data;
using System.Data.OleDb;

...

DataSet ds;
string sCSVFile = "Input.csv";
string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\;Extended Properties='text;HDR=No;FMT=Delimited'";
OleDbConnection conn = new OleDbConnection(sConnectionString);
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM ["+ sCSVFile + "]", conn);

try
{
conn.Open();
ds = new DataSet("MyDataSet");
da.FillSchema(ds, SchemaType.Source, sCSVFile);
da.Fill(ds, sCSVFile);

... //Do something with dataset

conn.Close();

}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
return;
}

return;

Hope this helps.

Tom.
0
 
LVL 2

Author Comment

by:wazzajs
ID: 9727521
Sorry for the late reply, had to work on something else so never got the chance to check for response...

your solution works great!

thanks for your time...

wazzajs
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question