我想用来自SQL数据库的数据填充PDF上的某些字段,我有一个可以使用的数据访问类但我无法从行中获取值:
DataAccess DA = new DataAccess();
DataSet S = DA.CashData();
DataTable Cash = S.Tables[0];
DataTable Other = S.Tables[1];
DataTable Check = S.Tables[2];
DataTable Else = S.Tables[3];
string s = "";
foreach (DataRow row in Cash.Rows)
{
foreach (DataColumn col in Cash.Columns)
{
for (int i = 0; i < Cash.Columns.Count; i++)
{
DataRow cashRow = Cash.Rows[i];
s = s + cashRow[0].ToString() + ";";
}
}
Console.ReadLine();
}
string[] data = s.Split(';');
cell32.AddElement(new Paragraph(""));
cell32.AddElement(new Paragraph(data[0]));
cell32.AddElement(new Paragraph(data[1]));
列显示数据但行不
答案 0 :(得分:1)
如果我正确理解了你的源代码,你的循环中的行执行错误,请考虑这个编辑过的源代码:
DataAccess DA = new DataAccess();
DataSet S = DA.CashData();
DataTable Cash = S.Tables[0];
DataTable Other = S.Tables[1];
DataTable Check = S.Tables[2];
DataTable Else = S.Tables[3];
string s = "";
foreach (DataRow row in Cash.Rows)
{
for (int i = 0; i < row.Columns.Count; i++)
{
s += row[0].ToString() + ";";
}
Console.ReadLine();
}
string[] data = s.Split(';');
cell32.AddElement(new Paragraph(""));
cell32.AddElement(new Paragraph(data[0]));
cell32.AddElement(new Paragraph(data[1]));