1

我收到以下错误:

缺少对象或列名称或为空。对于 SELECT INTO 语句,验证每一列都有一个名称。对于其他语句,请查找空别名。不允许使用定义为 "" 或 [] 的别名。添加名称或单个空格作为别名。

对于下面的查询显示:

if (comboBox1.SelectedIndex > -1) {

    // comboBox1.UpdateLayout();

    SqlCom.CommandText = "select  distinct  table_name from [" +comboBox1.Text + "].information_schema.columns c inner join [" + comboBox1.Text + "].sys.tables t on c.table_name = t.name order by table_name";

    using (SqlDR = SqlCom.ExecuteReader()) {

        comboBox2.Items.Clear();

        while (SqlDR.Read()) {

            comboBox2.Items.Add(SqlDR.GetString(0));}

        }
}

知道这里有什么问题吗?

我填充combobox1 whit:`SqlCom.CommandText =“从sys.databases中选择*,其中database_id> 4按名称排序”;这工作正常

4

2 回答 2

2

正如您在其中一条评论中提到的,实际查询是:

select distinct table_name 
from .information_schema.columns c 
inner .sis.tables t 
on c.table_name = t.name order by table_name 

这意味着您的两个组合框值都是空的。探索你失去价值的地方,你会得到答案。

于 2013-08-21T17:12:40.097 回答
1

So if I read this right...

Combo Box 1 is a list of database names...

Combo Box 2 is a list of table names...

You're trying to look-up a list of tables for a given database to populate Combo Box 2, right? If so...

  1. Why the joined tables in your query? And why bother with table aliases with such a short query? Why not just select a list of tables from sys.tables?
  2. Parameters Parameters Parameters, as your commentators have already said
于 2013-08-21T16:50:36.003 回答