wince5.0 +SQlite 的基本操作




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;

using System.Data.sqlite;
using System.Data.Common;
using System.Data.sqlTypes;

namespace sqltest
{
    public partial class Form1 : Form
    {
        public String strConn;
        sqliteConnection connection = new sqliteConnection();
        sqliteCommand command = new sqliteCommand();
        public Form1()
        {
            InitializeComponent();
            strConn = "test.db3";
            File.Delete("test.db3");
            try
            {
                sqliteConnection.CreateFile("test.db3");//创建数据库
//                sqliteConnection connection = new sqliteConnection("Data 

//Source=test.db3");//创建一个对test.db3的连接
                connection.ConnectionString = "Data Source=" + strConn;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void button1_Click(object sender,EventArgs e)
        {
            if (button1.Text == "连接数据库")
            {
                try
                {
                    connection.open();//连接数据库(无法找到066.dll出错的解决方法:将066.dll
//拷到wince中sqlite程序目录下)
                    MessageBox.Show("数据库连接成功");
                }
                catch (Exception ep)
                {
                    MessageBox.Show(ep.ToString());
                }
                button1.Text = "关闭数据库";
            }
            else
            {
                try
                {
                    connection.Close();//连接数据库(无法找到066.dll出错的解决方法:将

//066.dll拷到wince中sqlite程序目录下)
                    MessageBox.Show("数据库断开连接");
                }
                catch (Exception ep)
                {
                    MessageBox.Show(ep.ToString());
                }
                button1.Text = "连接数据库";
            }
        }

        private void button2_Click(object sender,EventArgs e)
        {
             try
            {
                command.Connection = connection;
                command.CommandText = "CREATE TABLE [admin] ([ID] VARCHAR(50),[TEL] VARCHAR(50),[Password] VARCHAR(50));";
                int x = command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void button3_Click(object sender,EventArgs e)
        {
            sqliteTransaction ta = connection.BeginTransaction();
            try
            {
               
                for (int i = 0; i < 100; i++)
                {
                    command.CommandText = "insert into admin(ID,TEL,Password) VALUES('3','4','5')";


                    command.ExecuteNonQuery();
                }

                    /*                command.CommandText = "insert into admin

(ID,Password) VALUES('333','444','555')";
                                    int x = command.ExecuteNonQuery();*/
                    ta.Commit();
            }
            catch (Exception ex)
            {
                ta.Rollback();
                MessageBox.Show(ex.ToString());
            }
        }

        private void button4_Click(object sender,EventArgs e)
        {
            string id,tel,pword = "";
            textBox1.Text = "";
            try 
            {
                command.CommandText = "select * from admin";
 //               int x = command.ExecuteNonQuery();
                sqliteDataReader reader = command.ExecuteReader();//把与command的对应的reader对象转递给reader。


                while (reader.Read())
                {
                    id = reader.GetValue(0).ToString();
                    tel = reader.GetValue(1).ToString();
                    pword = reader.GetValue(2).ToString();
                    textBox1.Text += id + "---" + tel + "---" + pword + "\r\n";
                }
                reader.Close();
                reader.dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能