none
Need help using a datatable to manage a csv file RRS feed

  • Question

  • Hi, i'm new to ado.net and i need help with some concepts and a little guidance.
    First i would like to describe my situation:
    I'm using .net cf 2.0.
    I have a csv file which contains a few columns, one of them is a DateTime column, the csv is sorted descending by this column.
    I am developing an application which need to display the data  of the csv file, and be able to add new rows to it in the right place, and remove rows as the user requests.

    What i did is using the OpenNETCF datatextadapter to load the csv data to a datatable, i can use this datatextadapter also to update the csv file back.
    One problem was that the datatable gets all data from the csv file as strings, so i added a new column to the datatable and filled it with the time parsed to dateTime.
    i defined this column as the primary key, and when i want to add a new row i can first use find to see if it's already there, and if not, i can add it.
    now here are my questions:

    1. can i convert a datatable column type from strings to DateTime, so i wouldn't need to add a new seperate column for that?
    2. how can i sort the datatable in place so it will really change the order of the rows of the datatable itself so i can also keep the csv file sorted?
    3.or better way than question 2, how can i add a row inside the datatable in a specific place so all further rows will go one place down?
    any better ways to do that, or suggestions will be welcome.
    I appreciate your help.

    Edited:
     i used Datatable.Rows.insertat(Datarow row, int location) for inserting a row in a specific location, that answers question 2, so question 3 is void.
    for question 1 i will use what i already did, anyway i won't use find and  i will loop on the table to find the right place to insert the row , and if i have to insert it at all.
    Friday, December 5, 2008 8:09 PM