DataTable.ImportRow is not adding rows

后端 未结 4 1798
我寻月下人不归
我寻月下人不归 2021-01-12 07:23

I\'m trying to make a DataTable and then add a couple rows to it. Here\'s my code:

using System;
using System.Collections.Generic;
using System.Linq;
using          


        
相关标签:
4条回答
  • 2021-01-12 07:53

    Try this code:

    dt.Rows.Add(dr)

    0 讨论(0)
  • 2021-01-12 07:54

    You first need to add the row:

     dt.Rows.Add(dr);
    

    Then you must call below method to commit it:

     dt.AcceptChanges();
    
    0 讨论(0)
  • 2021-01-12 07:59

    If the row is detached (as it is when it is first created) ImportRows fails silently (no exception) - to be able to import rows you have to Add it into the table. Afterwards you can import it into other tables.

    0 讨论(0)
  • 2021-01-12 08:01

    Its May Help you

    DataTable table = new DataTable();
    table.Columns.Add("Dosage", typeof(int));
        table.Columns.Add("Drug", typeof(string));
        table.Columns.Add("Patient", typeof(string));
        table.Columns.Add("Date", typeof(DateTime));
    
        //
        // Here we add five DataRows.
        //
        table.Rows.Add(25, "Indocin", "David", DateTime.Now);
        table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
        table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
        table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
        table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
    
    0 讨论(0)
提交回复
热议问题