winform程序中使用SQLite

前端之家收集整理的这篇文章主要介绍了winform程序中使用SQLite前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

cs文件:

 
 
  1. usingSystem;
  2. usingSystem.Collections.Generic;
  3. usingSystem.ComponentModel;
  4. usingSystem.Data;
  5. usingSystem.Drawing;
  6. usingSystem.Linq;
  7. usingSystem.Text;
  8. usingSystem.Windows.Forms;
  9. usingSystem.Data.sqlite;
  10. usingDevComponents.DotNetBar;
  11. namespaceMyWinForm
  12. {
  13. publicpartialclassForm1:Office2007Form
  14. {
  15. publicForm1()
  16. {
  17. InitializeComponent();
  18. }
  19. privatevoidForm1_Load(objectsender,EventArgse)
  20. {
  21. sqliteConnectiondbConnection=newsqliteConnection("DataSource=../../test.db;");
  22. sqliteCommanddbCommand=newsqliteCommand("SELECT*FROMuser",dbConnection);
  23. dbCommand.CommandType=CommandType.Text;
  24. sqliteDataAdapterdbDataAdapter=newsqliteDataAdapter(dbCommand);
  25. DataSetdataSet=newDataSet();
  26. dbDataAdapter.Fill(dataSet,"user");
  27. dataGridView1.DataSource=dataSet.Tables["user"];
  28. }
  29. }
  30. }

设计器生成:

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

运行界面:

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

猜你在找的Sqlite相关文章