DataTable中,标题Caption,ColumnName的区别

想要获取 dataTable 的标题时,会遇到

1 string c_str = ds1.Tables[0].Columns[j].Caption; 

1 string col_nam = ds1.Tables[0].Columns[j].ColumnName;

二者的区别,动  Caption,该列内容仍在,而一旦动了  ColumnName,则整列内容跟随变化,

不形象的例子 ColumnName 是身份证号 ,Caption  等于姓名;

 1                       for (int j = 2; j < ds1.Tables[0].Columns.Count; j++)
 2                         {
 3                             string r_str = ds1.Tables[0].Rows[i][j].ToString();
 4                             //string c_str = ds1.Tables[0].Columns[j].Caption;  
 5                             ///上下两句有什么区别呢?Caption是标题,改了不影响列;/ColumnsName一旦更改,列跟着变
 6                             string col_nam = ds1.Tables[0].Columns[j].ColumnName;
 7                             string xzq_str = ds1.Tables[0].Rows[i][0].ToString();
 8                             string sqlStr = "Update " + shtTabNam + " set " + col_nam + " = '" + r_str + "' Where XZQDM = '" + xzq_str + "'";
 9                             SQLiteCommand sCmd = new SQLiteCommand(sqlStr, dbConn);
10                             sCmd.ExecuteNonQuery();
11                         }

 

posted @ 2022-06-03 23:47  橙香夜雨  阅读(500)  评论(0编辑  收藏  举报