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.DotNetBar;
- namespace MyWinForm
- {
- public partial class Form1 : Office2007Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- SQLiteConnection dbConnection = new SQLiteConnection("Data Source=../../test.db;");
- SQLiteCommand dbCommand = new SQLiteCommand("SELECT * FROM user", dbConnection);
- dbCommand.CommandType = CommandType.Text;
- SQLiteDataAdapter dbDataAdapter = new SQLiteDataAdapter(dbCommand);
- DataSet dataSet = new DataSet();
- dbDataAdapter.Fill(dataSet, "user");
- dataGridView1.DataSource = dataSet.Tables["user"];
- }
- }
- }
设计器生成:
- namespace MyWinForm
- {
- partial class Form1
- {
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Windows 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要
- /// 使用代码编辑器修改此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
- this.bindingSource1 = new System.Windows.Forms.BindingSource(this.components);
- this.dataGridView1 = new System.Windows.Forms.DataGridView();
- this.id = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.uname = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.password = new System.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(new System.Windows.Forms.DataGridViewColumn[] {
- this.id,
- this.uname,
- this.password});
- this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.dataGridView1.Location = new System.Drawing.Point(0, 0);
- this.dataGridView1.Name = "dataGridView1";
- this.dataGridView1.ReadOnly = true;
- this.dataGridView1.RowTemplate.Height = 23;
- this.dataGridView1.Size = new System.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 = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.BottomLeftCornerSize = 15;
- this.BottomRightCornerSize = 15;
- this.ClientSize = new System.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 += new System.EventHandler(this.Form1_Load);
- ((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- private System.Windows.Forms.BindingSource bindingSource1;
- private System.Windows.Forms.DataGridView dataGridView1;
- private System.Windows.Forms.DataGridViewTextBoxColumn id;
- private System.Windows.Forms.DataGridViewTextBoxColumn uname;
- private System.Windows.Forms.DataGridViewTextBoxColumn password;
- }
- }
运行界面:
注意需要引用System.Data.SQLite.dll