Results 1 to 4 of 4

Thread: Ado.Net: Reorder columns in a DataTable

  1. #1
    Join Date
    Sep 2010
    Posts
    20

    Ado.Net: Reorder columns in a DataTable

    I have a DataTable derived from a physical table (in this case Access). On the other hand I have a lot of text files that I have to 'import' in this table, with way records. The problem I have is that some files, I import the fields are 'disordered' and when I import the data, give me problems. Example:
    Table Destination: Fields A, B, C, D, E, F.

    Origin1 file: Fields A, B, D, E, F, C.

    Origin2 file: Fields A, B, C, D, E, F

    The import was done by reading line by line, that when the fields are sorted correctly is straightforward and fast:

    Dim lines As String () = Split (fst.ReadLine, vbTab)

    Tabla.Rows.Add (lines)
    But if the fields are messed up, I am 'adding' information field 'mistakenly'. If I 'ordered' DataTable fields in the order of the file, they would be charged correctly, and dump them to the database, all would be right. The problem is that I have not managed to sort Table.Columns (without of course losing its association with the base table.) Is this possible? I had thought also if you can change 'partnership' between column and column datatable 'real' database, but I do not see how.

  2. #2
    Join Date
    Jan 2009
    Posts
    143

    Re: Ado.Net: Reorder columns in a DataTable

    It seems that you are trying to map the text file that define a class. Then with this burden might send it to datatable in the order you need because we have loaded properties. As far as I know it should use the properties :
    Dt.NewRow DataRow row = ();

    row.NameColumn = value1;

    row.NameColumn = value2;

    dt.Rows.Add (row);
    This is just one example, but it is something like add each row to the datatable, if so because it affects the order of columns could be used,
    Dt.NewRow DataRow row = ();

    row.NameColumn2 = value2;

    row.NameColumn1 = value1;

    row.NameColumn3 = value3;

    dt.Rows.Add (row);

  3. #3
    Join Date
    Sep 2010
    Posts
    20

    Re: Ado.Net: Reorder columns in a DataTable

    For my problem, not me because my source files are not fixed (they are from an external source and are moving to my chagrin), and have many intermediate lines to eliminate and / or processing, etc. to get good data, but eventually got to the point that I mentioned in first post. I have some data 'row' that I have to put in a datatable, which I do well. Dim lines As String () = Split (fst.ReadLine, vbTab) 'I read the line, separated by tabs. Table.Rows.Add (lines) 'Insert the line in the table IF YOU ARE IN THE SAME ORDER!. When not in the same order as the data source, I have 3 options:
    1. Sort the data read each record. Files are 30,000, 100,000 records, which penalizes me down. Furthermore, having to process 14 columns and 'rearrange' the data each time.
    2. Use field names variables: Row.Item ("FieldName") = lines (n). Which also penalizes me down.
    3. Order del DataTable fields, so that only I have to do once you start reading the book and go. No speed penalty (in principle)
    That is why I'm looking for if: Can 'rearrange' the fields in a DataTable? Or failing that: Re-Mapping the allocation of the column from the DataTable and the actual table?

  4. #4
    Join Date
    Feb 2009
    Posts
    105

    Re: Ado.Net: Reorder columns in a DataTable

    If we are talking delimited text file (in your case, tab characters), all about mapping the column names of these text files to coincide with the fields or columns in your DataTable. Imagine you have a DataTable whose columns are in the following order:
    A, B, C, D, E, F
    All columns delimited text files you open, you have to map them in the same order, so that the values of each column is inserted in the appropriate column of the DataTable. But of course! For all this to work, rather than reading line by line text files, you have to open them directly using the text ISAM Microsoft Jet database engine or Microsoft ACE, just as you do when you want to read any table in your Access database. For starters, if the file fields are tab delimited text, and in order not to complicate one's life, in the same folder where the file resides text you want to open, you must have a configuration file schema necessarily will be called "Schema.ini" where to save the settings for delimited text files.

Similar Threads

  1. How can you reorder pictures in Facebook ?
    By Naotau in forum Technology & Internet
    Replies: 5
    Last Post: 19-11-2010, 11:35 PM
  2. How to sort a datatable
    By Udayachal in forum Software Development
    Replies: 6
    Last Post: 23-01-2010, 01:23 PM
  3. Nested DataTable for GridView
    By Renderman21 in forum Software Development
    Replies: 3
    Last Post: 08-05-2009, 02:08 PM
  4. Exporting datatable to excel with ADO.net
    By Sanket07 in forum Software Development
    Replies: 2
    Last Post: 03-02-2009, 05:52 PM
  5. How can i export datatable to excel
    By Leena in forum Software Development
    Replies: 3
    Last Post: 30-01-2009, 11:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,308,180.61647 seconds with 17 queries