comboBox停止显示SQL表
问题描述:
我以前工作的代码,从数据库中提取表突然没有显示在我的组合框中。通过comboBox可以看到数据正在被拉出,但是项目不可见。如下图所示:comboBox停止显示SQL表
这是我的代码拉表:
private void fillOutputFile()
{
try
{
string connectionString = "Data Source=bid;Initial Catalog=BI;Integrated Security=True";
using (SqlConnection con2 = new SqlConnection(connectionString))
{
con2.Open();
string query = "Select table_name from INFORMATION_SCHEMA.columns";
SqlCommand cmd2 = new SqlCommand(query, con2);
SqlDataReader dr2 = cmd2.ExecuteReader();
while (dr2.Read())
{
int col = dr2.GetOrdinal("TABLE_NAME");
comboBox5.Items.Add(dr2[col].ToString());
// con2.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show("Your Windows Credentials does not have the rights to access/write to this table./nPlease contact your DB Administrator");
}
}
答
我知道这看起来很奇怪,但它实际上可能工作。将您的项目复制到PC上的其他位置。完成之后,删除旧的项目。将新项目复制到已删除项目的位置。打开VS并尝试调试您再次复制的项目。它可能工作
+0
我不能相信这实际上起作用。任何想法为什么这解决了它? –
+1
@AdamNewman我在想也许这个目录在某种程度上被破坏了?我不确定,过去我只是搞乱了,而且工作 – Jevon
调试代码并查看查询是否返回记录 – imsome1
确认您正在访问正确的数据库。除此之外,你的代码似乎没有问题 –