我有一个包含数据的DataTable。为简化起见,我会说我的DataTable看起来像这样:
DataTable AccDT = new DataTable();
string CmdTxt = "Select CBL.BENEFIT_ID as BenefitID, ";
CmdTxt = CmdTxt + "CBL.BENEFIT_CATEGORY as Category, CBL.BENEFIT_PROVISION as Provision, ";
CmdTxt = CmdTxt + "FROM CSTAPP_O.D_Benefit CBL ";
OracleCommand cmd = new OracleCommand(CmdTxt, connection);
cmd.Connection = connection;
cmd.CommandText = CmdTxt;
cmd.CommandType = CommandType.Text;
OracleDataAdapter da = new OracleDataAdapter(cmd);
da.Fill(AccDT);
现在,我想用一个名为“Category”的字段的值填充一个数组。我该怎么做呢?
答案 0 :(得分:1)
应将列值放入数组中。
AccDT.AsEnumerable().Select(r => r.Field<string>("Category")).ToArray();
答案 1 :(得分:0)
假设你的数组是一个字符串,
for (int i = 0; i < AcctDT.Rows.Count; i++)
{
someArray[i] = AcctDT.Rows[i]["Category"].ToString();
}
您只需按名称引用列即可。