protected void getListTop(int classID) {
DataTable dt=listTop.getListTop(classID);
dt.Columns.Add("Ntitle");//增加一列Ntitle string sql = "select * from NewsNotes where NewsclassID =" + classID.ToString();
DataTable dtxxx = new DataTable();
OleDbConnection con = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["connectionstring"].ToString());
OleDbDataAdapter da = new OleDbDataAdapter(sql, con);
da.Fill(dtxxx);
if (dt.Rows.Count > 0)
{
DataRow dr = dt.Rows[0]; dr["Ntitle"] = dtxxx.Rows[0][2].ToString();//把Ntitle 从数据取出来!
this.RepeartListTop.DataSource = dt;
this.RepeartListTop.DataBind();
}
}
请问下我把这个梆定在REpear里可以把dt里面的内容全循环出来了.
为什么Ntitle的内容只能显示第一条呢?
DataTable dt=listTop.getListTop(classID);
dt.Columns.Add("Ntitle");//增加一列Ntitle string sql = "select * from NewsNotes where NewsclassID =" + classID.ToString();
DataTable dtxxx = new DataTable();
OleDbConnection con = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["connectionstring"].ToString());
OleDbDataAdapter da = new OleDbDataAdapter(sql, con);
da.Fill(dtxxx);
if (dt.Rows.Count > 0)
{
DataRow dr = dt.Rows[0]; dr["Ntitle"] = dtxxx.Rows[0][2].ToString();//把Ntitle 从数据取出来!
this.RepeartListTop.DataSource = dt;
this.RepeartListTop.DataBind();
}
}
请问下我把这个梆定在REpear里可以把dt里面的内容全循环出来了.
为什么Ntitle的内容只能显示第一条呢?
["Ntitle"] = dtxxx.Rows[0][2].ToString();//把Ntitle 从数据取出来!
你只给第一行的Ntitle 列赋值了,其他都没赋值
{
DataRow dr = dt.Rows[0]; dr["Ntitle"] = dtxxx.Rows[0][2].ToString();//把Ntitle 从数据取出来!
this.RepeartListTop.DataSource = dt;
this.RepeartListTop.DataBind();
}
这段有问题,应该在 dt中做循环啊。
foreach (DataRow drData in dt.Rows)
{
dr["Ntitle"] = drData[2].ToString();//把Ntitle 从数据取出来!
}
this.RepeartListTop.DataSource = dt;
this.RepeartListTop.DataBind();
dt.Columns.Add("Ntitle");//增加一列Ntitle
这个地方不能这样做
(1) 首先该列没有字段类型(int,string...)
建议你改成动态创建Datatable(2)你下面的只去第一行 dr["Ntitle"] = dtxxx.Rows[0][2].ToString();//把Ntitle 从数据取出来!的title
你这方法我试了下..不行啊..我是想从数据库里取出一行值的时候就加上另外一个表里的Ntitle的值..我也知道我取出来的是另外一个表的第一行第3列的值.
{
dr["Ntitle"] = drData[2].ToString();//把Ntitle 从数据取出来!
dt.add(dr);//类似的意思,你改一下正确语句。
}
this.RepeartListTop.DataSource = dt;
this.RepeartListTop.DataBind();
{
dr["Ntitle"] = drData[2].ToString();//把Ntitle 从数据取出来!
dt.Rows.Add(dr);//类似的意思,你改一下正确语句。
}
this.RepeartListTop.DataSource = dt;
this.RepeartListTop.DataBind();
DataRow dr = dt.Rows[i];
dr["Ntitle"] = dtxxx.Rows[i][2].ToString();
}
{
DataRow dr = dt.Rows[0]; dr["Ntitle"] = dtxxx.Rows[0][2].ToString();//把Ntitle 从数据取出来!
this.RepeartListTop.DataSource = dt;
this.RepeartListTop.DataBind();
} 你的这个if只对第一行进行了操作,其他行步没操作
这样
if (dt.Rows.Count > 0)
{
DataRow dr = dt.Rows[0]; dr["Ntitle"] = dtxxx.Rows[0][2].ToString();//把Ntitle 从数据取出来!
this.RepeartListTop.DataSource = dt;
this.RepeartListTop.DataBind();
}
这段有问题,应该在 dt中做循环啊。
foreach (DataRow drData in dt.Rows)
{
dr["Ntitle"] = drData[2].ToString();//把Ntitle 从数据取出来!
}
this.RepeartListTop.DataSource = dt;
this.RepeartListTop.DataBind();