步步为营-58-SQLite的使用
时间:2021-07-01 10:21:17
帮助过:17人阅读
System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Fuxi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(
object sender, EventArgs e)
{
//00 构造数据的集合
List<ManagerInfo> listManager =
new List<ManagerInfo>
( );
//01-显示数据
//01-01 连接字符串"物理路径;版本号":
string connStr =
@"data source=F:\Users\home\Documents\Visual Studio 2013\PaoDingJieNiu\PDJN.db;version=3;";
//01-02 创建连接字符串
using (SQLiteConnection conn =
new SQLiteConnection( connStr))
{
//01-03 查询语句
SQLiteCommand cmd =
new SQLiteCommand(
"select * from ManagerInfo",conn);
//01-04 执行command
conn.Open();
SQLiteDataReader reader =
cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
listManager.Add(new ManagerInfo()
{
Mid = Convert.ToInt32(reader[
"mid"]),
Mname = reader[
"mname"].ToString(),
Mpwd = reader[
"mpwd"].ToString(),
Mtype =Convert.ToInt32( reader[
"mtype"])
});
}
}
//02 显示到datagridView上
dataGridView1.DataSource =
listManager;
}
}
}
}
代码示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Fuxi
{
public partial class ManagerInfo
{
public int Mid { get; set; }
public string Mname { get; set; }
public string Mpwd { get; set; }
public int Mtype { get; set; }
}
}
ManagerInfo
步步为营-58-SQLite的使用
标签:class reader idt task nbsp 执行 visual 分享 代码示例