zoukankan      html  css  js  c++  java
  • 步步为营-58-SQLite的使用

    说明:文档型关系数据库,多用于移动端

    1.1 添加引用

     ` 1.1.1  System.Data.SQLite.xml

      1.1.2  System.Data.SQLite.dll

    1.2 连接字符串的设置

                string connStr = @"data source=F:UsershomeDocumentsVisual Studio 2013PaoDingJieNiuPDJN.db;version=3;"; 

    using 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:UsershomeDocumentsVisual Studio 2013PaoDingJieNiuPDJN.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

  • 相关阅读:
    c++第二十八天
    pyDay16
    c++第二十七天
    c++第二十六天
    WinForm 应用程序的打包与部署
    更换Winform 皮肤(下)----完全GDI+绘制
    更换Winform 皮肤(上)----使用现有皮肤
    KeyValuePair用法(转)
    C#中HashTable的用法
    WinForm----DataGridview---连接数据库,以及双击一条数据,显示信息到Label控件,也可以是TextBox控件。
  • 原文地址:https://www.cnblogs.com/YK2012/p/6860873.html
Copyright © 2011-2022 走看看