dt.tables.add [da]出错; [英] Error at the dt.tables.add[da];

查看:57
本文介绍了dt.tables.add [da]出错;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  protected   void  Page_Load(对象发​​件人,EventArgs e)
{

如果(!IsPostBack)
{

var da = objlinq.Facs.ToList();
DataTable dt = new DataTable();
dt.Tables.Add [da];
dt.Columns.Add( Did);
lblDid.Text = Request.QueryString [ Did]。ToString();


if (lblDid.Text == ds.Tables [ 0 ]。行[ 0 ] [ ])
{

GridView1.DataSource = da;
GridView1.DataBind();
}





我的尝试:



protected void Page_Load(object sender,EventArgs e)

{



if(!IsPostBack)

{



var da = objlinq.Facs.ToList();

DataTable dt = new DataTable();

dt.Tables.Add [da];

dt.Columns.Add(Did);

lblDid.Text = Request.QueryString [ Did]。ToString();





if(lblDid.Text == ds.Tables [0] .Rows [0 ] [没有])

{



GridView1.DataSource = da;

GridView1.DataBind( );

}

解决方案

嗯。该代码看起来像你猜测并希望在这里:

1) dt 是一个DataTable,因此它没有Tables属性。这是针对DataSet的。

2)无论 objling.Facs 返回,我很确定它赢了;涉及DataTables的集合 - 所以 da 将是这些对象的列表。

3)添加是一个方法,而不是数组,所以你需要圆括号而不是方括号。

4)添加将一个项添加到一个集合中,AddRange是用于将项目集合添加到不同的集合。



正是你在这里尝试做什么我不确定 - 有太多相互矛盾的错误需要确定 - 所以我建议你退后一步,想想你想要实现的目标,并从一开始就重新开始! :笑:

protected void Page_Load(object sender, EventArgs e)
  {

      if(!IsPostBack)
      {

   var da=objlinq.Facs.ToList();
   DataTable dt = new DataTable();
   dt.Tables.Add[da];
   dt.Columns.Add("Did");
   lblDid.Text = Request.QueryString["Did"].ToString();


   if (lblDid.Text == ds.Tables[0].Rows[0]["Did"])
   {

       GridView1.DataSource = da;
       GridView1.DataBind();
   }



What I have tried:

protected void Page_Load(object sender, EventArgs e)
{

if(!IsPostBack)
{

var da=objlinq.Facs.ToList();
DataTable dt = new DataTable();
dt.Tables.Add[da];
dt.Columns.Add("Did");
lblDid.Text = Request.QueryString["Did"].ToString();


if (lblDid.Text == ds.Tables[0].Rows[0]["Did"])
{

GridView1.DataSource = da;
GridView1.DataBind();
}

解决方案

Um. That code looks like you are guessing and hoping here:
1) dt is a DataTable, so it doesn't have a Tables property. That's for DataSets instead.
2) Whatever objling.Facs returns, I'm pretty sure it won;t involve a collection of DataTables - so da will be a List of whatever those objects are.
3) Add is a method, not an array, so you need round brackets instead of square ones.
4) Add adds a single item to a collection, AddRange is used to add collections of items to a different collection.

Exactly what you are trying to do here I'm not sure - there are too many conflicting mistakes to be sure - so I'd suggest you take a step back, think about what you are trying to achieve and and start again from the beginning! :laugh:


这篇关于dt.tables.add [da]出错;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆