none
Slow performance ????????????? RRS feed

  • Question

  • I'm trying to get some rows from one tabel - PERSONER - and add some of the columns to another table - PERSONER_2

    I have got myself 2 datasets by dragging the tables to the dataset designer and then made this code:
    1             DataSet_SourceTableAdapters.PERSONERTableAdapter tblSource  
    2                 = new TestCopyDataFromOneTableToAnother.DataSet_SourceTableAdapters.PERSONERTableAdapter();  
    3             DataSet_Source.PERSONERDataTable tbl = new DataSet_Source.PERSONERDataTable();  
    4             tblSource.Fill(tbl);  
    5             DataSet_DestinationTableAdapters.PERSONER_2TableAdapter tblDestination =  
    6                 new TestCopyDataFromOneTableToAnother.DataSet_DestinationTableAdapters.PERSONER_2TableAdapter();  
    7  
    8             for (int i = 0; i < tbl.Count; i++)  
    9             {  
    10                 label1.Text = i.ToString();  
    11                  
    12                 tblDestination.Insert(tbl.Rows[i].ItemArray.GetValue(0).ToString()  
    13                                      , tbl.Rows[i].ItemArray.GetValue(1).ToString()  
    14                                      , tbl.Rows[i].ItemArray.GetValue(2).ToString()  
    15                                      , decimal.Parse(tbl.Rows[i].ItemArray.GetValue(5).ToString())  
    16                                      , tbl.Rows[i].ItemArray.GetValue(8).ToString()  
    17                                      );  
    18                 label1.Refresh();  
    19             }  
    20  

    I think too hard to find the columns by their index number - better if I could use the name of the column/field

    Is there a better solution ?
    - with a minimum of code !!!!!

    Best regards KSor, Denmark
    Saturday, January 31, 2009 10:27 AM

Answers

  • Now I got a way to reference the columns by their names:
    1             DataSet_SourceTableAdapters.PERSONERTableAdapter tblSource  
    2                 = new TestCopyDataFromOneTableToAnother.DataSet_SourceTableAdapters.PERSONERTableAdapter();  
    3             DataSet_Source.PERSONERDataTable tbl = new DataSet_Source.PERSONERDataTable();  
    4             tblSource.Fill(tbl);  
    5             DataSet_DestinationTableAdapters.PERSONER_2TableAdapter tblDestination =  
    6                 new TestCopyDataFromOneTableToAnother.DataSet_DestinationTableAdapters.PERSONER_2TableAdapter();  
    7             for (int i = 0; i < tbl.Count; i++)  
    8             {  
    9                 label1.Text = i.ToString();  
    10                 tblDestination.Insert(tbl.Rows[i].ItemArray.GetValue(tbl.Columns.IndexOf("CPR-NR")).ToString()  
    11                                     , tbl.Rows[i].ItemArray.GetValue(tbl.Columns.IndexOf("Fornavn")).ToString()  
    12                                     , tbl.Rows[i].ItemArray.GetValue(tbl.Columns.IndexOf("Efternavn")).ToString()  
    13                                     , decimal.Parse(tbl.Rows[i].ItemArray.GetValue(tbl.Columns.IndexOf("Årsløn")).ToString())  
    14                                     , tbl.Rows[i].ItemArray.GetValue(tbl.Columns.IndexOf("Køn")).ToString()  
    15                                     );  
    16                 label1.Refresh();  
    17             }  
    18  
    Is this the "right" way to do it ?

    Best regards KSor, Denmark
    • Marked as answer by Ksor Saturday, January 31, 2009 5:24 PM
    Saturday, January 31, 2009 2:12 PM

All replies

  • Oh ... I got it - there ARE colunm names in the tbl .... but no way to get the value of the column - right ?

    But anyway - is there a SHORTER code for the transfering of data from one table to another ?

     


    Best regards KSor, Denmark
    Saturday, January 31, 2009 11:02 AM
  • Now I got a way to reference the columns by their names:
    1             DataSet_SourceTableAdapters.PERSONERTableAdapter tblSource  
    2                 = new TestCopyDataFromOneTableToAnother.DataSet_SourceTableAdapters.PERSONERTableAdapter();  
    3             DataSet_Source.PERSONERDataTable tbl = new DataSet_Source.PERSONERDataTable();  
    4             tblSource.Fill(tbl);  
    5             DataSet_DestinationTableAdapters.PERSONER_2TableAdapter tblDestination =  
    6                 new TestCopyDataFromOneTableToAnother.DataSet_DestinationTableAdapters.PERSONER_2TableAdapter();  
    7             for (int i = 0; i < tbl.Count; i++)  
    8             {  
    9                 label1.Text = i.ToString();  
    10                 tblDestination.Insert(tbl.Rows[i].ItemArray.GetValue(tbl.Columns.IndexOf("CPR-NR")).ToString()  
    11                                     , tbl.Rows[i].ItemArray.GetValue(tbl.Columns.IndexOf("Fornavn")).ToString()  
    12                                     , tbl.Rows[i].ItemArray.GetValue(tbl.Columns.IndexOf("Efternavn")).ToString()  
    13                                     , decimal.Parse(tbl.Rows[i].ItemArray.GetValue(tbl.Columns.IndexOf("Årsløn")).ToString())  
    14                                     , tbl.Rows[i].ItemArray.GetValue(tbl.Columns.IndexOf("Køn")).ToString()  
    15                                     );  
    16                 label1.Refresh();  
    17             }  
    18  
    Is this the "right" way to do it ?

    Best regards KSor, Denmark
    • Marked as answer by Ksor Saturday, January 31, 2009 5:24 PM
    Saturday, January 31, 2009 2:12 PM