手机版
你好,游客 登录 注册
背景:
阅读新闻

C# 内嵌数据库 SQLite

[日期:2012-03-13] 来源:Linux社区  作者:hongsejiaozhu [字体:大 中 小]

Winform的测试界面和代码如下。

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. using System.Data.SQLite;  
  10.   
  11. namespace SQliteTest  
  12. {  
  13.     public partial class Form1 : Form  
  14.     {  
  15.         public Form1()  
  16.         {  
  17.             InitializeComponent();  
  18.         }  
  19.   
  20.         private void button2_Click(object sender, EventArgs e)  
  21.         {  
  22.             string Sqlstr = "INSERT INTO [Users] VALUES(@username,@mobile)";  
  23.             SQLiteParameter[] canshu = new SQLiteParameter[]{  
  24.                         DAL.SQLiteHelper.CreateSqliteParameter("@username",DbType.String,50,this.textBox1.Text),  
  25.                         DAL.SQLiteHelper.CreateSqliteParameter("@mobile",DbType.String,50,this.textBox2.Text)  
  26.                       };  
  27.             DAL.SQLiteHelper.ExecuteNonQuery(Sqlstr, canshu);  
  28.             Bangding();  
  29.   
  30.         }  
  31.   
  32.         public void Bangding()  
  33.         {  
  34.             SQLiteParameter[] canshu1 = new SQLiteParameter[] { DAL.SQLiteHelper.CreateSqliteParameter("@id", DbType.Int32, 4, 1) };  
  35.             string Sqlstr = "select * from users";  
  36.             this.dataGridView1.DataSource = DAL.SQLiteHelper.ExecuteDataset(Sqlstr, canshu1).Tables[0];  
  37.               
  38.         }  
  39.   
  40.     }  
  41. }  

项目文件

没有做性能测试,应该问题不大。 紧紧做入门,保存下来以便自己日后会用到。

linux
相关资讯       C#  sqlite 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款