Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >Using sqlite with .NET

Using sqlite with .NET

作者头像
张善友
发布于 2018-01-31 02:44:01
发布于 2018-01-31 02:44:01
6520
举报
文章被收录于专栏:张善友的专栏张善友的专栏

The other day I found that there is a .NET wrapper for sqlite. sqlite is a very cool embeddable SQL-92 database engine. It's a single library that gives you a very fast, very scalable (2TB), single file, multi-user database. I thought the .NET wrapper is exceptionally handy because ADO is slow, and is hard to use (compared to this) and a HUGE overkill for smaller apps. It lets smaller apps have a real relational database without huge numbers of dependencies, complicated installs, or the complexity of ADO. Here is a really quick example program I wrote to try it out:

代码语言:js
AI代码解释
复制
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using SQLite.NET;

namespace WindowsApplication2
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.ListBox listBox1;
        private System.ComponentModel.Container components = null;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Button button1;
        private SQLiteClient db;

        public Form1()
        {
            db = new SQLiteClient("test.db");
            InitializeComponent();
            UpdateList();
        }

        public void UpdateList()
        {
            SQLiteResultSet results;

            results = db.Execute("select name, phone from people order by name;");
            listBox1.Items.Clear();
            foreach(ArrayList row in results.Rows)
            {
                listBox1.Items.Add(row[0]);
            }
        }

        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // listBox1
            // 
            this.listBox1.Location = new System.Drawing.Point(8, 8);
            this.listBox1.Name = "listBox1";
            this.listBox1.Size = new System.Drawing.Size(136, 199);
            this.listBox1.TabIndex = 0;
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(192, 24);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(120, 20);
            this.textBox1.TabIndex = 1;
            this.textBox1.Text = "textBox1";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(320, 24);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(72, 16);
            this.button1.TabIndex = 2;
            this.button1.Text = "button1";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(408, 349);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.listBox1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            db.Execute("insert into people values ('" + textBox1.Text.Replace("'","''") + "','111');");
            UpdateList();
        }
    }
}

http://jclement.ca/devel/dotnet/sqlite.html

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2006-01-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
控件属性和InitializeComponent()关系:
大家好,我是架构君,一个会写代码吟诗的架构师。今天说一说控件属性和InitializeComponent()关系:,希望能够帮助大家进步!!!
Java架构师必看
2022/03/21
4391
控件属性和InitializeComponent()关系:
(二十三)c#Winform自定义控件-等待窗体
GitHub:https://github.com/kwwwvagaa/NetWinformControl
冰封一夏
2019/09/11
9980
(二十三)c#Winform自定义控件-等待窗体
(十五)c#Winform自定义控件-键盘(二)
GitHub:https://github.com/kwwwvagaa/NetWinformControl
冰封一夏
2019/09/11
2.3K0
(十五)c#Winform自定义控件-键盘(二)
(七)c#Winform自定义控件-进度条
GitHub:https://github.com/kwwwvagaa/NetWinformControl
冰封一夏
2019/09/11
6740
(七)c#Winform自定义控件-进度条
(五)c#Winform自定义控件-复选框
GitHub:https://github.com/kwwwvagaa/NetWinformControl
冰封一夏
2019/09/11
7580
(五)c#Winform自定义控件-复选框
解决msmq接收远程主机私有队列消息的问题!
通过调用windows\system32\mqoa.dll 这个Message Queuing ActiveX Interface API函数就可以做到; 下面是一个简单的例子供参考; using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using MSMQ; namespace MyTest {     /// <summ
阿新
2018/04/13
2.4K0
c#基于Tablet pc实现的手写输入
需要安装Tablet pc,win7的话 直接在控制面板》程序和应用》添加组建里面勾选上添加
冰封一夏
2019/09/11
1.2K0
C#-TextBox-登录窗口密码不可见—ShinePans[通俗易懂]
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/161502.html原文链接:https://javaforall.cn
全栈程序员站长
2022/09/09
1.4K0
C#-TextBox-登录窗口密码不可见—ShinePans[通俗易懂]
C# 使用QRCoder生成二维码
最近瞎琢磨的一些小东西,也算是一个比较完整的二维码生成了,上手也很快,可自行扩展。 现在生成二维码有多种方式,我使用的是QRCoder。
郑子铭
2024/04/15
4570
C# 使用QRCoder生成二维码
C#通过FtpWebResponse 编写GUI 简易 FTP客户端
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; using System.Net; using System.IO; class FtpClientForm : Form { public FtpClientForm() { Initializ
用户7705674
2021/11/03
8740
c# winfrom 可折叠的树形控件
首先需要一个可绑定实体 [Serializable] public class TreeNodeModel { private Image _nodePic; /// <summary> /// 设置图标 /// </summary> public Image NodelPic { get { return _nodePic; } set { _no
冰封一夏
2019/09/11
2.4K0
在树莓派用C#+Winform实现传感器监测
Raspberry Pi 3B+ 树莓派GPIO扩展板 3.5寸电容触摸屏(GPIO接口) 土壤湿度传感器(GPIO接口) 光照传感器(GPIO接口) 由于作品已经交上去了 这里只能先放个以前的图
沙漠尽头的狼
2021/12/01
1K0
在树莓派用C#+Winform实现传感器监测
从Component对象到CodeDom——舞动你的Code系列(1)
我们经常会有这样的需求或者想法:动态的生成或者修改代码。当然,我们可以把代码看成字符串而直接修改,但是这种做法也未免太生硬了,能解决的问题有限;而另一个方式就是CodeDom。 CodeDom是强大的!我们感谢微软,给我们提供了强大的描述面向对象语言的框架;我们感谢微软,给我们提供了能够根据CodeDom生成代码或者程序集的CodeDomProvider;可惜微软没有给我们提供能够从object或者代码生成CodeDom的能力。 关于CodeDom的知识本文不过多涉及、感兴趣的童鞋可以阅读MSDN或者博客园
葡萄城控件
2018/01/10
7470
windows计算器
usingSystem;usingSystem.Drawing;usingSystem.Win运维
Java架构师必看
2021/03/22
1.4K0
(二十四)c#Winform自定义控件-单标题窗体
GitHub:https://github.com/kwwwvagaa/NetWinformControl
冰封一夏
2019/09/11
4780
(二十四)c#Winform自定义控件-单标题窗体
【C#】分享一个可携带附加消息的增强消息框MessageBoxEx
--------------201806111122更新---------------
AhDung
2018/09/13
2K0
【C#】分享一个可携带附加消息的增强消息框MessageBoxEx
(十一)c#Winform自定义控件-列表
GitHub:https://github.com/kwwwvagaa/NetWinformControl
冰封一夏
2019/09/11
1.3K0
(十一)c#Winform自定义控件-列表
(二十)c#Winform自定义控件-有后退的窗体
GitHub:https://github.com/kwwwvagaa/NetWinformControl
冰封一夏
2019/09/11
4420
(二十)c#Winform自定义控件-有后退的窗体
(四十九)c#Winform自定义控件-下拉框(表格)
GitHub:https://github.com/kwwwvagaa/NetWinformControl
冰封一夏
2019/09/09
1.7K0
(四十九)c#Winform自定义控件-下拉框(表格)
c#QQ连连看辅助
游戏辅助有三种方法,一种是读内存,这个不知道怎么分析,还有一种是获取封包,这个分析起来复杂,最后一种是图片识别再分析,这里采用最后一种 图片识别来做。
冰封一夏
2019/09/11
6420
相关推荐
控件属性和InitializeComponent()关系:
更多 >
领券
社区富文本编辑器全新改版!诚邀体验~
全新交互,全新视觉,新增快捷键、悬浮工具栏、高亮块等功能并同时优化现有功能,全面提升创作效率和体验
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文