Tuesday, May 3, 2011

How can i solve this error:"Column 'ASSET' does not belong to table ."?

How can i solve this error:"Column 'ASSET' does not belong to table ." ? i really learn it is belong this table: i want to do that:

if(mydataset.hasgot(dr["asset"].tostring()))
{
// do something
}

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                DataRow dr_ = tbl.NewRow();

                if (ds.Tables[0].Columns.Contains(dr_["ASSET"].ToString()))
                         dr_["ASSET"] = ds.Tables[0].Rows[i]["ASSET"].ToString(); //dr["ASSET"].ToString();
                  tbl.Rows.Add(dr_);
            }

            DataSet ds_ = new DataSet();
            ds_.Tables.Add(tbl);

my error:"Column 'ASSET' does not belong to table .". Please look codes:ds.Tables[0].Columns.Contains(dr_["ASSET"].ToString())



how can I control my colums which are includes "Asset"?

From stackoverflow
  • dr_["ASSET"].ToString() returns a string representation of whatever happens to be in the DataRow dr_ in column named "ASSET", which is obviously not what you need. Therefore, here's the correct one:

    if(ds.Tables[0].Columns.Contains("ASSET"))
    
    Phsika : Thanks you are correct!

0 comments:

Post a Comment