1
我有一個加載表名稱的DataGridView
。獲取表在構造函數中被調用。我有9個表存儲在.sdf數據庫中。當它加載時,我將所有表格至少列出81次。我如何顯示每個表名之一?我正在使用SqlCe 3.5和C#2010 Express。這裏是我的代碼:查看DataGridView中的所有SQL表格
DataTable dt = new DataTable();
private void getTables(object sender, EventArgs e)
{
dataGridView1.DataSource = dt;
string strConnect = @"Data Source=|DataDirectory|\LWADataBase.sdf";
using (SqlCeConnection con = new SqlCeConnection(strConnect))
{
con.Open();
using (SqlCeCommand com = new SqlCeCommand("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES", con))
{
using (SqlCeDataReader reader = com.ExecuteReader())
{
SqlCeDataAdapter da = new SqlCeDataAdapter();
da.SelectCommand = com;
while (reader.Read())
{
da.Fill(dt);
}
}
}
}
}