今天偶尔有个东西要用到2维数组,发现不会,搞来搞去搞了半天,还是上网google了资料。
总结一下。
定义变量的方法,
private string[] ColumnsList = {
"序号|rowid","主帐户|masteraccount","主帐号|childaccount","卡号|cardno",
"户名|name","客户号|crmid","科目号|stocktype",
"原金额|orgincount","发生额|currcount","新金额|newcount","状态|state"
};
private string[,] dataList = {
{"1","6624885718651234","000001","057400000000000001","张三风","32240001","805001","100","1","101","正常"},
{"2","6624885718651234","000002","057400000000000002","张三风","32240002","805001","1000","94","1094","正常"},
{"3","6624885718651234","000003","057400000000000003","张三风","32240003","805001","109","9","118","挂失"},
{"4","6624885718651234","000004","057400000000000004","张三风","32240004","805001","234","5","239","注销"},
};
遍历添加到Table中
DataTable dt = new DataTable();
for(int i=0;i {
string[] templist = ColumnsList[i].Split('|');
if (templist.Length != 2) continue;
dt.Columns.Add(templist[1].Trim(), typeof(string));
}
dt.AcceptChanges();
for (int i = 0; i < 4; i++)
{
DataRow dr = dt.NewRow();
for(int j=0;j {
string[] templist = ColumnsList[j].Split('|');
if (templist.Length != 2) continue;
dr[templist[1].Trim()] = dataList[i, j].Trim();
}
dt.Rows.Add(dr);
}
dt.AcceptChanges();
记一下,防止以后忘记!
总结一下。
定义变量的方法,
private string[] ColumnsList = {
"序号|rowid","主帐户|masteraccount","主帐号|childaccount","卡号|cardno",
"户名|name","客户号|crmid","科目号|stocktype",
"原金额|orgincount","发生额|currcount","新金额|newcount","状态|state"
};
private string[,] dataList = {
{"1","6624885718651234","000001","057400000000000001","张三风","32240001","805001","100","1","101","正常"},
{"2","6624885718651234","000002","057400000000000002","张三风","32240002","805001","1000","94","1094","正常"},
{"3","6624885718651234","000003","057400000000000003","张三风","32240003","805001","109","9","118","挂失"},
{"4","6624885718651234","000004","057400000000000004","张三风","32240004","805001","234","5","239","注销"},
};
遍历添加到Table中
DataTable dt = new DataTable();
for(int i=0;i {
string[] templist = ColumnsList[i].Split('|');
if (templist.Length != 2) continue;
dt.Columns.Add(templist[1].Trim(), typeof(string));
}
dt.AcceptChanges();
for (int i = 0; i < 4; i++)
{
DataRow dr = dt.NewRow();
for(int j=0;j {
string[] templist = ColumnsList[j].Split('|');
if (templist.Length != 2) continue;
dr[templist[1].Trim()] = dataList[i, j].Trim();
}
dt.Rows.Add(dr);
}
dt.AcceptChanges();
记一下,防止以后忘记!
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/794934/viewspace-573152/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/794934/viewspace-573152/