load csv file

hi guys!
I have a question about CSV file.
I have a problem loading data to my Datagrid.
How can I specify which column to get data from and which column of the grid to load data to
BTW, I'm using Memory Stream and UTF-8 encoding in loading my csv file.

Please help!Thanks!


Answer this question

load csv file

  • Slim

    Thanks for your reply!
    Tried your suggestion.
    I used the Microsoft Text Driver of Odbc and it seems that it automatically gets the first row as the column header and this is not exactly what I want.
    Is there a way where I can just specify which column to take data from and load data to

    And another thing, does OleDB driver( ) has something like Microsoft Text driver of
    Odbc (don't know if this is the right question....=(  )


    Thanks again for your time.

  • StatlerW

    hi again!
    I have a question about generating the query statement.
    What if I set the HDR = No and I want to add to the query statement
    a condition like If the first column has a value or not, how do
    I do this when the column header is not set

    Thanks!


  • Splinter Cell

    You could user ADO.NET to load your csv file.

  • Andreas Schweizer

    Hi,

    Hmmm. I haven't tried it. But you could check the datatable and see what is the generated fieldnames. It could be expr1, expr2, etc.... Or you could just manipulate your datatable and remove all the rows that you don't want to be included...




    cheers,

    Paul June A. Domag


  • Garyrg9

    Thanks Paul!

  • P S Hall

    Thanks!
    I checked the generate field name and it seems to be using F1, F2..etc...

    Thanks again!

  • abstar

    Hi,

    Try this...

     OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + System.IO.Path.GetDirectoryName(strFileName) +"; Extended Properties = \"Text;HDR=YES;FMT=Delimited\"");
     conn.Open();
     OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM " + System.IO.Path.GetFileName(strFileName), conn);
     DataSet ds = new DataSet("Temp"); 
     adapter.Fill(ds);
     DataTable tb = ds.Tables[0];

     datagrid1.DataSource = tb;


    cheers,


    Paul June A. Domag


  • load csv file