开发者

C# SQL Columns into ComboBox

开发者 https://www.devze.com 2022-12-13 06:48 出处:网络
My SQL query isn\'t dropping anything into the combobox. The connection seems to be made but the while loop doesn\'t seem to work. Can anybody tell me what it wrong?

My SQL query isn't dropping anything into the combobox. The connection seems to be made but the while loop doesn't seem to work. Can anybody tell me what it wrong?

string sqltable开发者_运维百科 = ("dbo.SLTDS_C"+id+"_table");  

SqlConnection con = new SqlConnection("Data Source=" + server   + ";Initial Catalog=" + database + ";Integrated Security=" + security);  
con.Open();  

string sqldatapull = ("select name from syscolumns where id = object_id('" + sqltable + "') order by name asc");

SqlCommand cmd = new SqlCommand(sqldatapull, con);

cmd.CommandType = CommandType.Text;

SqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())  
{  
    sqldatapull = dr[0].ToString();  
    comboBox1.Items.Add(sqldatapull);  
}  

dr.Close();  
con.Close();  

Correction code:

string sqldatapull = ("select name from syscolumns where id = object_id('" + sqltable + "') order by name asc");


It's because you're including dbo. as part of the table name. If you run

SELECT * FROM INFORMATION_SCHEMA.COLUMNS

You will see that the table names have no schema in the TABLE_NAME column.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号