基本信息
源码名称:winform 读取 access数据库 数据 翻页功能实现 附源码
源码大小:0.11M
文件格式:.zip
开发语言:C#
更新时间:2013-04-23
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
c#读取access数据库实例 实现了翻页功能
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace DataBase3 { /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Label label4; private System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1; private System.Data.OleDb.OleDbCommand oleDbSelectCommand1; private System.Data.OleDb.OleDbCommand oleDbInsertCommand1; private System.Data.OleDb.OleDbCommand oleDbUpdateCommand1; private System.Data.OleDb.OleDbCommand oleDbDeleteCommand1; private System.Data.OleDb.OleDbConnection oleDbConnection1; private DataBase3.DataSet1 dataSet11; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form1() { // Windows 窗体设计器支持所必需的 InitializeComponent(); // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.dataSet11 = new DataBase3.DataSet1(); this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox3 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.label4 = new System.Windows.Forms.Label(); this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter(); this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand(); this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection(); this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand(); this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand(); this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand(); ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(24, 24); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(67, 18); this.label1.TabIndex = 0; this.label1.Text = "用户名:"; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(24, 84); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(52, 18); this.label2.TabIndex = 1; this.label2.Text = "地址:"; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(24, 144); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(60, 18); this.label3.TabIndex = 2; this.label3.Text = "Email:"; // // textBox1 // this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "user.username")); this.textBox1.Location = new System.Drawing.Point(104, 17); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(256, 25); this.textBox1.TabIndex = 3; this.textBox1.Text = ""; // // dataSet11 // this.dataSet11.DataSetName = "DataSet1"; this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN"); this.dataSet11.Namespace = "http://www.tempuri.org/DataSet1.xsd"; // // textBox2 // this.textBox2.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "user.address")); this.textBox2.Location = new System.Drawing.Point(104, 77); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(256, 25); this.textBox2.TabIndex = 4; this.textBox2.Text = ""; // // textBox3 // this.textBox3.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "user.Email")); this.textBox3.Location = new System.Drawing.Point(104, 137); this.textBox3.Name = "textBox3"; this.textBox3.Size = new System.Drawing.Size(256, 25); this.textBox3.TabIndex = 5; this.textBox3.Text = ""; // // button1 // this.button1.Location = new System.Drawing.Point(35, 192); this.button1.Name = "button1"; this.button1.TabIndex = 6; this.button1.Text = "上一条"; this.button1.TextAlign = System.Drawing.ContentAlignment.TopCenter; this.button1.Click = new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(283, 192); this.button2.Name = "button2"; this.button2.TabIndex = 7; this.button2.Text = "下一条"; this.button2.TextAlign = System.Drawing.ContentAlignment.TopCenter; this.button2.Click = new System.EventHandler(this.button2_Click); // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(139, 197); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(121, 18); this.label4.TabIndex = 8; this.label4.Text = "当前第x条/共x条"; // // oleDbDataAdapter1 // this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1; this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1; this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1; this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping("Table", "user", new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping("username", "username"), new System.Data.Common.DataColumnMapping("address", "address"), new System.Data.Common.DataColumnMapping("Email", "Email")})}); this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1; // // oleDbDeleteCommand1 // this.oleDbDeleteCommand1.CommandText = "DELETE FROM [user] WHERE (编号 = ?) AND (Email = ? OR ? IS NULL AND Email IS NULL) " "AND (address = ? OR ? IS NULL AND address IS NULL) AND (username = ?)"; this.oleDbDeleteCommand1.Connection = this.oleDbConnection1; this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_编号", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), "编号", System.Data.DataRowVersion.Original, null)); this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Email", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Email", System.Data.DataRowVersion.Original, null)); this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Email1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Email", System.Data.DataRowVersion.Original, null)); this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_address", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "address", System.Data.DataRowVersion.Original, null)); this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_address1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "address", System.Data.DataRowVersion.Original, null)); this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_username", System.Data.OleDb.OleDbType.VarWChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "username", System.Data.DataRowVersion.Original, null)); // // oleDbConnection1 // this.oleDbConnection1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=E:\Project\DataBase3\bin\Debug\test.mdb;Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False"; //MessageBox.Show(System.Windows.Forms.Application.StartupPath); this.oleDbConnection1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=" System.Windows.Forms.Application.StartupPath @"\test.mdb;Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False"; // // oleDbInsertCommand1 // this.oleDbInsertCommand1.CommandText = "INSERT INTO [user] (username, address, Email, 编号) VALUES (?, ?, ?, ?)"; this.oleDbInsertCommand1.Connection = this.oleDbConnection1; this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("username", System.Data.OleDb.OleDbType.VarWChar, 20, "username")); this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("address", System.Data.OleDb.OleDbType.VarWChar, 50, "address")); this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Email", System.Data.OleDb.OleDbType.VarWChar, 50, "Email")); this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("编号", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), "编号", System.Data.DataRowVersion.Current, null)); // // oleDbSelectCommand1 // this.oleDbSelectCommand1.CommandText = "SELECT username, address, Email, 编号 FROM [user]"; this.oleDbSelectCommand1.Connection = this.oleDbConnection1; // // oleDbUpdateCommand1 // this.oleDbUpdateCommand1.CommandText = "UPDATE [user] SET username = ?, address = ?, Email = ?, 编号 = ? WHERE (编号 = ?) AND" " (Email = ? OR ? IS NULL AND Email IS NULL) AND (address = ? OR ? IS NULL AND ad" "dress IS NULL) AND (username = ?)"; this.oleDbUpdateCommand1.Connection = this.oleDbConnection1; this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("username", System.Data.OleDb.OleDbType.VarWChar, 20, "username")); this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("address", System.Data.OleDb.OleDbType.VarWChar, 50, "address")); this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Email", System.Data.OleDb.OleDbType.VarWChar, 50, "Email")); this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("编号", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), "编号", System.Data.DataRowVersion.Current, null)); this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_编号", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(10)), ((System.Byte)(0)), "编号", System.Data.DataRowVersion.Original, null)); this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Email", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Email", System.Data.DataRowVersion.Original, null)); this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Email1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Email", System.Data.DataRowVersion.Original, null)); this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_address", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "address", System.Data.DataRowVersion.Original, null)); this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_address1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "address", System.Data.DataRowVersion.Original, null)); this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_username", System.Data.OleDb.OleDbType.VarWChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "username", System.Data.DataRowVersion.Original, null)); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(8, 18); this.ClientSize = new System.Drawing.Size(392, 234); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.label4, this.button2, this.button1, this.textBox3, this.textBox2, this.textBox1, this.label3, this.label2, this.label1}); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "数据库导航"; this.Load = new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit(); this.ResumeLayout(false); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void ShowPosition() { int iCnt; int iPos; iCnt = this.BindingContext[dataSet11, "user"].Count; iPos = this.BindingContext[dataSet11, "user"].Position 1; if(iCnt == 0) { label4.Text = "(No records)"; } else { label4.Text = "当前第" iPos.ToString() "条/共" iCnt.ToString() "条"; } } private void Form1_Load(object sender, System.EventArgs e) { dataSet11.Clear(); oleDbDataAdapter1.Fill(dataSet11); } private void button1_Click(object sender, System.EventArgs e) { this.BindingContext[dataSet11, "user"].Position -=1; ShowPosition(); } private void button2_Click(object sender, System.EventArgs e) { this.BindingContext[dataSet11, "user"].Position =1; ShowPosition(); } } }