cs文件:
- usingSystem;
- usingSystem.Collections.Generic;
- usingSystem.ComponentModel;
- usingSystem.Data;
- usingSystem.Drawing;
- usingSystem.Linq;
- usingSystem.Text;
- usingSystem.Windows.Forms;
- usingSystem.Data.sqlite;
- usingDevComponents.DotNetBar;
- namespaceMyWinForm
- {
- publicpartialclassForm1:Office2007Form
- {
- publicForm1()
- {
- InitializeComponent();
- }
- privatevoidForm1_Load(objectsender,EventArgse)
- {
- sqliteConnectiondbConnection=newsqliteConnection("DataSource=../../test.db;");
- sqliteCommanddbCommand=newsqliteCommand("SELECT*FROMuser",dbConnection);
- dbCommand.CommandType=CommandType.Text;
- sqliteDataAdapterdbDataAdapter=newsqliteDataAdapter(dbCommand);
- DataSetdataSet=newDataSet();
- dbDataAdapter.Fill(dataSet,"user");
- dataGridView1.DataSource=dataSet.Tables["user"];
- }
- }
- }
设计器生成:
- namespaceMyWinForm
- {
- partialclassForm1
- {
- ///<summary>
- ///必需的设计器变量。
- ///</summary>
- privateSystem.ComponentModel.IContainercomponents=null;
- ///<summary>
- ///清理所有正在使用的资源。
- ///</summary>
- ///<paramname="disposing">如果应释放托管资源,为true;否则为false。</param>
- protectedoverridevoidDispose(booldisposing)
- {
- if(disposing&&(components!=null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #regionWindows窗体设计器生成的代码
- ///<summary>
- ///设计器支持所需的方法-不要
- ///使用代码编辑器修改此方法的内容。
- ///</summary>
- privatevoidInitializeComponent()
- {
- this.components=newSystem.ComponentModel.Container();
- System.ComponentModel.ComponentResourceManagerresources=newSystem.ComponentModel.ComponentResourceManager(typeof(Form1));
- this.bindingSource1=newSystem.Windows.Forms.BindingSource(this.components);
- this.dataGridView1=newSystem.Windows.Forms.DataGridView();
- this.id=newSystem.Windows.Forms.DataGridViewTextBoxColumn();
- this.uname=newSystem.Windows.Forms.DataGridViewTextBoxColumn();
- this.password=newSystem.Windows.Forms.DataGridViewTextBoxColumn();
- ((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
- this.SuspendLayout();
- //
- //dataGridView1
- //
- this.dataGridView1.AllowUserToAddRows=false;
- this.dataGridView1.AllowUserToDeleteRows=false;
- this.dataGridView1.BackgroundColor=System.Drawing.Color.White;
- this.dataGridView1.ColumnHeadersHeightSizeMode=System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- this.dataGridView1.Columns.AddRange(newSystem.Windows.Forms.DataGridViewColumn[]{
- this.id,
- this.uname,
- this.password});
- this.dataGridView1.Dock=System.Windows.Forms.DockStyle.Fill;
- this.dataGridView1.Location=newSystem.Drawing.Point(0,0);
- this.dataGridView1.Name="dataGridView1";
- this.dataGridView1.ReadOnly=true;
- this.dataGridView1.RowTemplate.Height=23;
- this.dataGridView1.Size=newSystem.Drawing.Size(344,191);
- this.dataGridView1.TabIndex=0;
- //
- //id
- //
- this.id.DataPropertyName="uid";
- this.id.HeaderText="用户标识";
- this.id.Name="id";
- this.id.ReadOnly=true;
- //
- //uname
- //
- this.uname.DataPropertyName="uname";
- this.uname.HeaderText="用户名";
- this.uname.Name="uname";
- this.uname.ReadOnly=true;
- //
- //password
- //
- this.password.DataPropertyName="password";
- this.password.HeaderText="密码";
- this.password.Name="password";
- this.password.ReadOnly=true;
- //
- //Form1
- //
- this.AutoScaleDimensions=newSystem.Drawing.SizeF(6F,12F);
- this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
- this.BottomLeftCornerSize=15;
- this.BottomRightCornerSize=15;
- this.ClientSize=newSystem.Drawing.Size(344,191);
- this.Controls.Add(this.dataGridView1);
- this.Icon=((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.Name="Form1";
- this.Text="用户资料";
- this.Load+=newSystem.EventHandler(this.Form1_Load);
- ((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- privateSystem.Windows.Forms.BindingSourcebindingSource1;
- privateSystem.Windows.Forms.DataGridViewdataGridView1;
- privateSystem.Windows.Forms.DataGridViewTextBoxColumnid;
- privateSystem.Windows.Forms.DataGridViewTextBoxColumnuname;
- privateSystem.Windows.Forms.DataGridViewTextBoxColumnpassword;
- }
- }
运行界面:
注意需要引用System.Data.sqlite.dll
原文链接:https://www.f2er.com/sqlite/202811.html