数据网格视图未从 SQL Server CE 填充数据

本文关键字:数据 Server CE 填充 SQL 数据网 网格 视图 | 更新日期: 2023-09-27 18:30:48

我在将数据填充到 datagridview 控件中时遇到问题。这是我的代码。

string sqlQuery = "SELECT * FROM Table;";
string source = "Data Source=E:''Documents''Database''Database.sdf;" +
                "Password=password;Persist Security Info=False;";
SqlCeDataAdapter dataAdapter = new SqlCeDataAdapter(sqlQuery, source);
SqlCeCommandBuilder commBuilder = new SqlCeCommandBuilder(dataAdapter);
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
dbBindSource.DataSource = table;
dbGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
dbGridView.ReadOnly = true;
dbGridView.DataSource = dbBindSource;

这是在表单加载上运行无济于事。任何人?

数据网格视图未从 SQL Server CE 填充数据

DataTable dataT;
BindingSource bindS;
using (SqlCeConnection yourConnection = new SqlCeConnection("Data Source=|DataDirectory|''YourDatabase.sdf")) {
    dataT = new DataTable();
    bindS = new BindingSource();    
    string query = "SELECT * FROM table01";
    SqlCeDataAdapter dA = new SqlCeDataAdapter(query, yourConnection);
    SqlCeCommandBuilder cBuilder = new SqlCeCommandBuilder(dA);
    dA.Fill(dataT);
    bindS.DataSource = dataT;
    DataGridView1.DataSource = bindS;
}

通过一个工作示例复活这一点,因为页面在谷歌上的排名并且因为它从未得到回答。

路径相对于执行目录。