之前正在使用的代码,从数据库中提取表格突然没有显示在我的comboBox中。可以通过comboBox看到数据被拉出但项目不可见。如下图所示:
这是我提取表格的代码:
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");
}
}