string dbFilePath = @"Data Source=你的数据库路径";
using (SQLiteConnection connection = new SQLiteConnection(dbFilePath))
{
connection.Open();
// 先将数据表中三列读取到一个gridControl中
string query = "SELECT [INDEX], [COUPLED], [MIX_RATIO] FROM BaseSeting";
using (SQLiteCommand command = new SQLiteCommand(query, connection))
{
using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(command))
{
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
// 将 DataTable 绑定到 gridControl1
gridControl1.DataSource = dataTable;
}
}
// 将部分数据绑定到另一个gridControl中
string query2 = "SELECT [BA_MIX], [TIME], [MIX_COUNT] FROM BaseSeting WHERE [INDEX] = 'A'";
using (SQLiteCommand command2 = new SQLiteCommand(query2, connection))
{
using (SQLiteDataAdapter adapter2 = new SQLiteDataAdapter(command2))
{
DataTable dataTable2 = new DataTable();
try
{
adapter2.Fill(dataTable2);
// 打印 dataTable2 内容
foreach (DataRow row in dataTable2.Rows)
{
Console.WriteLine($"BA_MIX: {row["BA_MIX"]}, TIME: {row["TIME"]}, MIX_COUNT: {row["MIX_COUNT"]}");
}
gridControl2.DataSource = dataTable2;
Console.WriteLine("左下角数据绑定成功");
Console.WriteLine("Rows count: " + dataTable2.Rows.Count);
}
catch (Exception ex)
{
Console.WriteLine("数据绑定失败: " + ex.Message);
}
}
}
用该方式首先记得一定要设置gridControl表的fileName属性与我的列绑定的数据字段一致
在DevExpress GridControl中:
- 使用FileNmae属性来设置列绑定的数据字段。
- 使用Caption 属性来设置显示的列标题。