C#调用SQLite数据库中数据,在datagridview中显示出来 程序代码 10
1个回答
展开全部
SQLiteConnection conn;
conn = new SQLiteConnection("Data Source=device.db");//创建数据库实例,指定文件位置
conn.Open();
DbText = "select address, name1, name2, name3, name4, onoffline, roomtemp, workmode, work_status, pw_on_off, pwconsume, alarm, updatetime, IpPort,devive_time from working";
SQLiteDataAdapter mAdapter = new SQLiteDataAdapter(DbText, conn);
DataTable dt = new DataTable();
mAdapter.Fill(dt);// 绑定数据到DataGridView
this.DataGridView1.AutoGenerateColumns = true;
DataGridView1.DataSource = dt;
conn.Close();
//DataGridView1.Columns[0].HeaderCell.Value = "序号";
DataGridView1.Columns[0].HeaderCell.Value = "设备编号";
DataGridView1.Columns[1].HeaderCell.Value = "安装位置1";
DataGridView1.Columns[2].HeaderCell.Value = "安装位置2";
DataGridView1.Columns[3].HeaderCell.Value = "安装位置3";
DataGridView1.Columns[4].HeaderCell.Value = "安装位置4";
DataGridView1.Columns[5].HeaderCell.Value = "在线状态";
DataGridView1.Columns[6].HeaderCell.Value = "室内温度";
DataGridView1.Columns[7].HeaderCell.Value = "工作模式";
DataGridView1.Columns[8].HeaderCell.Value = "工作状态";
DataGridView1.Columns[9].HeaderCell.Value = "设备启停";
DataGridView1.Columns[10].HeaderCell.Value = "总功耗";
DataGridView1.Columns[11].HeaderCell.Value = "报警状态";
DataGridView1.Columns[12].HeaderCell.Value = "更新时间";
DataGridView1.Columns[13].HeaderCell.Value = "IP地址端口";
DataGridView1.Columns[14].HeaderCell.Value = "设备时间";
//MessageBox.Show(Convert.ToString(DataGridView1.RowCount));
conn.Close();
conn = new SQLiteConnection("Data Source=device.db");//创建数据库实例,指定文件位置
conn.Open();
DbText = "select address, name1, name2, name3, name4, onoffline, roomtemp, workmode, work_status, pw_on_off, pwconsume, alarm, updatetime, IpPort,devive_time from working";
SQLiteDataAdapter mAdapter = new SQLiteDataAdapter(DbText, conn);
DataTable dt = new DataTable();
mAdapter.Fill(dt);// 绑定数据到DataGridView
this.DataGridView1.AutoGenerateColumns = true;
DataGridView1.DataSource = dt;
conn.Close();
//DataGridView1.Columns[0].HeaderCell.Value = "序号";
DataGridView1.Columns[0].HeaderCell.Value = "设备编号";
DataGridView1.Columns[1].HeaderCell.Value = "安装位置1";
DataGridView1.Columns[2].HeaderCell.Value = "安装位置2";
DataGridView1.Columns[3].HeaderCell.Value = "安装位置3";
DataGridView1.Columns[4].HeaderCell.Value = "安装位置4";
DataGridView1.Columns[5].HeaderCell.Value = "在线状态";
DataGridView1.Columns[6].HeaderCell.Value = "室内温度";
DataGridView1.Columns[7].HeaderCell.Value = "工作模式";
DataGridView1.Columns[8].HeaderCell.Value = "工作状态";
DataGridView1.Columns[9].HeaderCell.Value = "设备启停";
DataGridView1.Columns[10].HeaderCell.Value = "总功耗";
DataGridView1.Columns[11].HeaderCell.Value = "报警状态";
DataGridView1.Columns[12].HeaderCell.Value = "更新时间";
DataGridView1.Columns[13].HeaderCell.Value = "IP地址端口";
DataGridView1.Columns[14].HeaderCell.Value = "设备时间";
//MessageBox.Show(Convert.ToString(DataGridView1.RowCount));
conn.Close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询