winform程序中使用SQLite

 cs文件:

 


  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. using DevComponents.DotNetBar; 
  12.  
  13. namespace MyWinForm 
  14.     public partial class Form1 : Office2007Form 
  15.     { 
  16.         public Form1() 
  17.         { 
  18.             InitializeComponent(); 
  19.         } 
  20.  
  21.         private void Form1_Load(object sender, EventArgs e) 
  22.         { 
  23.             SQLiteConnection dbConnection = new SQLiteConnection("Data Source=../../test.db;"); 
  24.             SQLiteCommand dbCommand = new SQLiteCommand("SELECT * FROM user", dbConnection); 
  25.             dbCommand.CommandType = CommandType.Text; 
  26.             SQLiteDataAdapter dbDataAdapter = new SQLiteDataAdapter(dbCommand); 
  27.             DataSet dataSet = new DataSet(); 
  28.             dbDataAdapter.Fill(dataSet, "user"); 
  29.             dataGridView1.DataSource = dataSet.Tables["user"]; 
  30.         } 
  31.  
  32.     } 

设计器生成:

 


  1. namespace MyWinForm 
  2.     partial class Form1 
  3.     { 
  4.         /// <summary> 
  5.         /// 必需的设计器变量。 
  6.         /// </summary> 
  7.         private System.ComponentModel.IContainer components = null
  8.  
  9.         /// <summary> 
  10.         /// 清理所有正在使用的资源。 
  11.         /// </summary> 
  12.         /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 
  13.         protected override void Dispose(bool disposing) 
  14.         { 
  15.             if (disposing && (components != null)) 
  16.             { 
  17.                 components.Dispose(); 
  18.             } 
  19.             base.Dispose(disposing); 
  20.         } 
  21.  
  22.         #region Windows 窗体设计器生成的代码 
  23.  
  24.         /// <summary> 
  25.         /// 设计器支持所需的方法 - 不要 
  26.         /// 使用代码编辑器修改此方法的内容。 
  27.         /// </summary> 
  28.         private void InitializeComponent() 
  29.         { 
  30.             this.components = new System.ComponentModel.Container(); 
  31.             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); 
  32.             this.bindingSource1 = new System.Windows.Forms.BindingSource(this.components); 
  33.             this.dataGridView1 = new System.Windows.Forms.DataGridView(); 
  34.             this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); 
  35.             this.uname = new System.Windows.Forms.DataGridViewTextBoxColumn(); 
  36.             this.password = new System.Windows.Forms.DataGridViewTextBoxColumn(); 
  37.             ((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).BeginInit(); 
  38.             ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); 
  39.             this.SuspendLayout(); 
  40.             //  
  41.             // dataGridView1 
  42.             //  
  43.             this.dataGridView1.AllowUserToAddRows = false
  44.             this.dataGridView1.AllowUserToDeleteRows = false
  45.             this.dataGridView1.BackgroundColor = System.Drawing.Color.White; 
  46.             this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; 
  47.             this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { 
  48.             this.id, 
  49.             this.uname, 
  50.             this.password}); 
  51.             this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; 
  52.             this.dataGridView1.Location = new System.Drawing.Point(0, 0); 
  53.             this.dataGridView1.Name = "dataGridView1"
  54.             this.dataGridView1.ReadOnly = true
  55.             this.dataGridView1.RowTemplate.Height = 23; 
  56.             this.dataGridView1.Size = new System.Drawing.Size(344, 191); 
  57.             this.dataGridView1.TabIndex = 0; 
  58.             //  
  59.             // id 
  60.             //  
  61.             this.id.DataPropertyName = "uid"
  62.             this.id.HeaderText = "用户标识"
  63.             this.id.Name = "id"
  64.             this.id.ReadOnly = true
  65.             //  
  66.             // uname 
  67.             //  
  68.             this.uname.DataPropertyName = "uname"
  69.             this.uname.HeaderText = "用户名"
  70.             this.uname.Name = "uname"
  71.             this.uname.ReadOnly = true
  72.             //  
  73.             // password 
  74.             //  
  75.             this.password.DataPropertyName = "password"
  76.             this.password.HeaderText = "密码"
  77.             this.password.Name = "password"
  78.             this.password.ReadOnly = true
  79.             //  
  80.             // Form1 
  81.             //  
  82.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 
  83.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
  84.             this.BottomLeftCornerSize = 15; 
  85.             this.BottomRightCornerSize = 15; 
  86.             this.ClientSize = new System.Drawing.Size(344, 191); 
  87.             this.Controls.Add(this.dataGridView1); 
  88.             this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 
  89.             this.Name = "Form1"
  90.             this.Text = "用户资料"
  91.             this.Load += new System.EventHandler(this.Form1_Load); 
  92.             ((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).EndInit(); 
  93.             ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); 
  94.             this.ResumeLayout(false); 
  95.  
  96.         } 
  97.  
  98.         #endregion 
  99.  
  100.         private System.Windows.Forms.BindingSource bindingSource1; 
  101.         private System.Windows.Forms.DataGridView dataGridView1; 
  102.         private System.Windows.Forms.DataGridViewTextBoxColumn id; 
  103.         private System.Windows.Forms.DataGridViewTextBoxColumn uname; 
  104.         private System.Windows.Forms.DataGridViewTextBoxColumn password; 
  105.  
  106.     } 

 

运行界面:

 

winform程序中使用SQLite

注意需要引用System.Data.SQLite.dll

 




 本文转自 xcf007 51CTO博客,原文链接:http://blog.51cto.com/xcf007/426681,如需转载请自行联系原作者

上一篇:winform 使用SplashScreen窗口


下一篇:【Ext.Net学习笔记】01:在ASP.NET WebForm中使用Ext.Net