“列'abc'不属于表。 [英] "Column 'abc' does not belong to a table.
本文介绍了“列'abc'不属于表。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的组合框未加载并一直显示此错误
My combo box does not load and keeps showing this error
Column 'Item_GenName' does not belong to a table.
这是代码:
Here's the code:
void loadgeneric()
{
string constring = "Data Source=D-HOS-MIS2;Initial Catalog=Consignment_db;Persist Security Info=True;User ID=sa;Password=t.july.01";
string query = "select distinct convert(varchar,Item_GenName) from ItemMasterlistTable where datalength(Item_GenName) != 0";
SqlConnection con_db = new SqlConnection(constring);
SqlCommand cmd = new SqlCommand(query, con_db);
SqlDataReader reader;
try
{
DataTable gencombo = new DataTable();
con_db.Open();
reader = cmd.ExecuteReader();
gencombo.Load(reader);
foreach (DataRow row in gencombo.Rows)
{
Item_GenName.Items.Add(row["Item_GenName"]);
}
Item_GenName.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
Item_GenName.AutoCompleteSource = AutoCompleteSource.ListItems;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
我的尝试:
在提示此错误之前,我的sql只是
What I have tried:
Before it prompted this error, my sql was simply just
select Item_GenName from ItemMasterlist
我希望它能够检索非空和非重复的项目,这就是我查询结果的原因。
I wanted it to retrieve non-empty and non-duplicate items that's why I resulted to that query.
推荐答案
看看这一行:
Take a look at this line:
string query = "select distinct convert(varchar,Item_GenName) from ItemMasterlistTable where datalength(Item_GenName) != 0";
返回类似于:(无列名)
的内容。所以,改变如下:
This returns something like: (No column name)
. So, change it as follow:
string query = "select distinct convert(varchar,Item_GenName) AS Item_GenName from ItemMasterlistTable where datalength(Item_GenName) != 0";
然后你就可以引用列 Item_GenName
这篇关于“列'abc'不属于表。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文