SQLite的查询

时间:2023-10-12 22:29:20

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SQLite;

namespace _01复习1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            List<ManagerInfo> list = new List<ManagerInfo>();
            string connStr = @"data source=C:\Users\Administrator\Desktop\2015-05-13.NET就业班-三层项目+SVN\资料\ItcastCater.db;version=3;";
            using (SQLiteConnection conn = new SQLiteConnection(connStr))
            {
                using (SQLiteCommand cmd=new SQLiteCommand("select * from ManagerInfo",conn))
                {
                    conn.Open();
                    SQLiteDataReader reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            list.Add(new ManagerInfo()
                            {
                                MId = int.Parse(reader["MId"].ToString()),
                                MName = reader["MName"].ToString(),
                                MPwd = reader["MPwd"].ToString(),
                                MType = int.Parse(reader["MType"].ToString()),
                            });
                        }
                    }
                    reader.Close();
                    this.dataGridView1.DataSource = list;
                }   
            }
        }
    }
}