[英]C#, Looping through dataset and show each record from a dataset column
In C#, I'm trying to loop through my dataset to show data from each row from a specific column.在 C# 中,我试图遍历我的数据集以显示来自特定列的每一行的数据。 I want the get each date under the column name "TaskStart" and display it on a report, but its just shows the date from the first row for all rows can anybody help?我想在列名“TaskStart”下获取每个日期并将其显示在报告中,但它只显示所有行第一行的日期,有人可以帮忙吗?
foreach (DataTable table in ds.Tables)
{
foreach (DataRow dr in table.Rows)
{
DateTime TaskStart = DateTime.Parse(
ds.Tables[0].Rows[0]["TaskStart"].ToString());
TaskStart.ToString("dd-MMMM-yyyy");
rpt.SetParameterValue("TaskStartDate", TaskStart);
}
}
I believe you intended it more this way: 我相信你更喜欢这样:
foreach (DataTable table in ds.Tables)
{
foreach (DataRow dr in table.Rows)
{
DateTime TaskStart = DateTime.Parse(dr["TaskStart"].ToString());
TaskStart.ToString("dd-MMMM-yyyy");
rpt.SetParameterValue("TaskStartDate", TaskStart);
}
}
You always accessed your first row in your dataset. 您始终访问数据集中的第一行。
DateTime TaskStart = DateTime.Parse(dr["TaskStart"].ToString());
foreach (DataRow dr in ds.Tables[0].Rows)
{
//your code here
}
foreach (DataTable table in ds.Tables)
{
foreach (DataRow dr in table.Rows)
{
var ParentId=dr["ParentId"].ToString();
}
}
foreach (DataRow table in ds.Tables[0].Rows)
{
int ForType = Convert.ToInt32(table["Fortype"].ToString());
ds.Tables[0].DefaultView.RowFilter = "ForType ='" + ForType +"'";
rbtnQuestion.DataSource = ds.Tables[0].DefaultView;
rbtnQuestion.DataBind();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.