C# how to change data in DataTable?

后端 未结 3 907
无人共我
无人共我 2020-12-29 06:07

I\'v got some problem, I use DataTable to store my data in dataGridView. Data was inputed like this:

dt = new DataTable();
dt.Columns.Add(\"ID\", typeof(int)         


        
相关标签:
3条回答
  • 2020-12-29 06:22

    Try the SetField method:

    table.Rows[i].SetField(column, value);
    table.Rows[i].SetField(columnIndex, value);
    table.Rows[i].SetField(columnName, value);

    This should get the job done and is a bit "cleaner" than using Rows[i][j].

    0 讨论(0)
  • 2020-12-29 06:31

    dt.Rows[1].ItemArray gives you a copy of item arrays. When you modify it, you're not modifying the original.

    You can simply do this:

    dt.Rows[1][3] = "Value";
    

    ItemArray property is used when you want to modify all row values.

    ex.:

    dt.Rows[1].ItemArray = newItemArray;
    
    0 讨论(0)
  • 2020-12-29 06:35

    You should probably set the property dt.Columns["columnName"].ReadOnly = false; before.

    0 讨论(0)
提交回复
热议问题