zoukankan      html  css  js  c++  java
  • C#如何改变DataTable中的数据?

    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));
    dt.Columns.Add("par", typeof(string));
    dt.Columns.Add("max", typeof(int));
    dt.Columns.Add("now", typeof(int));
    
    dt.Rows.Add(new object[] { id++,i + " " + j++, strarr[0], strarr[1] }); // ... etc etc
    
    dataGridView1.DataSource = dt;

    now I want to do some changes, I use code:

    dt.Rows[1].ItemArray[3] = "VALUE";

    When I debug, ItemArray represents the row I want to, so its okey, but still I can't do any changes, whats wrong ? How to update DataTable ??? I'm googling and nothing 

    解决方案:

    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].

  • 相关阅读:
    02_虚拟机参数
    01_java虚拟机基础入门
    03_模板消息
    Redis 实现分布式锁
    01_微信小程序支付
    python产生随机字符串
    输出的编码
    jmeter MD5加密
    vscode 插件推荐
    appium自动化安装(二)
  • 原文地址:https://www.cnblogs.com/windy3417/p/13691089.html
Copyright © 2011-2022 走看看