wince5.0 +SQlite 的基本 *** 作

wince5.0 +SQlite 的基本 *** 作,第1张

概述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.Diagn
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());            }        }    }}
总结

以上是内存溢出为你收集整理的wince5.0 +SQlite 的基本 *** 作全部内容,希望文章能够帮你解决wince5.0 +SQlite 的基本 *** 作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/1175341.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-02
下一篇2022-06-02

发表评论

登录后才能评论

评论列表(0条)

    保存