列'abc'不属于表问题? [英] Column 'abc' does not belong to table problem?

查看:98
本文介绍了列'abc'不属于表问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

0
下来投票

最爱

我比较两个DataTable,如果结果为false我将行添加到我的数据库表中。如果表数据库为空它可以工作,但是当我有值时,我得到列'标签'不属于表。第一个DataTable数据是从数据库表填充的。



比较代码如下:



0 down vote
favorite
I am comparing two DataTable, if the result is false I add row to my database table. If the table database is empty it works, but when I have values in it, I got "Column 'Tags' does not belong to table". The first DataTable data is Filled from database table.

the code of comparing is the following:

DataTable result = new DataTable(); 
result.Columns.Add("Tags", typeof(string));

 for (int k = 0; k < result.Rows.Count; k++)
 {
     for (int j = 0; j < tableTags.Rows.Count; j++)
      {
         if (tableTags.Rows[k]["Tags"].ToString().Equals(result.Rows[j]["TagName"].ToString()))
          {
            continue;
          }
         else
         {
           AddTags(result.Rows[k]["Tags"].ToString());
           break;
          }
      }
   }

推荐答案

你写道:

You wrote:
if (tableTags.Rows[k]["Tags"].ToString().Equals(result.Rows[j]["TagName"].ToString()))





它应该是:



It should be:

if (tableTags.Rows[k]["TagName"].ToString().Equals(result.Rows[j]["Tags"].ToString()))





您命名结果列变量Tags;我以为你只是换了他们的名字。为什么不给它们相同的名字?



另一个可能的解决方案是在第一行放置一个断点并在调试模式下启动解决方案。然后逐行查看您声明的变量实际包含的内容。



You named the column of result variable "Tags"; I supposed you just switched their names. Why not giving them the same name?

Another possible solution is to put a breakpoint on the first line and launch the solution in debug mode. Then see line by line what the variables you declare actually contain.


您好,这是一个示例代码,用于比较两个数据表:



Hi, Here is a sample code to do the comparison between 2 datatables:

DataRow dr;
        DataTable result = new DataTable();
        result.Columns.Add("Tags", typeof(string));
        //
        dr = result.NewRow();
        dr[0] = "a";
        result.Rows.Add(dr);
        //
        dr = result.NewRow();
        dr[0] = "b";
        result.Rows.Add(dr);
        //
        dr = result.NewRow();
        dr[0] = "c";
        result.Rows.Add(dr);
        result.Rows.Add();
        //
        DataTable tableTags = new DataTable();
        tableTags.Columns.Add("Tags", typeof(string));
        //
        dr = tableTags.NewRow();
        dr[0] = "A";
        tableTags.Rows.Add(dr);
        //
        dr = tableTags.NewRow();
        dr[0] = "e";
        tableTags.Rows.Add(dr);
        //        
        for (int k = 0; k < result.Rows.Count; k++)
        {
            var match = from tag in tableTags.AsEnumerable() where tag.Field<String>("Tags").ToLower() == result.Rows[k]["Tags"].ToString().ToLower() select tag;
            if (match.Any())
            {
                //The tag exists, write related code here.
            }
            else
            {
                //The tag does not exist, write related code here.
            }            
        }


这篇关于列'abc'不属于表问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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