加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

winform程序中使用SQLite

发布时间:2020-12-12 23:31:50 所属栏目:百科 来源:网络整理
导读:cs文件: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SQLite; using DevComponents.D

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读