dt.tables.add [da]出错; [英] Error at the 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) Whateverobjling.Facs
returns, I'm pretty sure it won;t involve a collection of DataTables - soda
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屋!