winform程序中使用SQLite

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

cs文件:

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

设计器生成:

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

运行界面:

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

原文链接:https://www.f2er.com/sqlite/202811.html

猜你在找的Sqlite相关文章