【SQL开源代码栏目提醒】:网学会员为需要SQL开源代码的朋友们搜集整理了C#操作Access的源程序 - 讲义教程相关资料,希望对各位网友有所帮助!
using System using System.Collections.Generic using System.ComponentModel using System.Data using System.Data.Common using System.Drawing using System.Linq using System.Data.OleDb using System.Text using System.Windows.Forms namespace Location public partial class Form1 : Form public Form1 InitializeComponent private void Form1_Loadobject sender EventArgs e this.Text Location System button1.Text 连接数据库 button2.Text 查询 button3.Text 退出 button4.Text 添加 button5.Text 删除 button6.Text 修改 label1.Text ID textBox1.Text 0 private void button1_Clickobject sender EventArgs e string ConStr ProviderMicrosoft.Jet.OLEDB.4.0data sourceLocation.mdb//创建OleDbConnection对象 OleDbConnection con new OleDbConnectionConStr con.Open if con.State ConnectionState.Open MessageBox.ShowAccess数据库的连接成功 Access数据库的连接 else MessageBox.ShowAccess数据库的连接失败 Access数据库的连接 con.Close private void button3_Clickobject sender EventArgs e //退出 this.Close private void button2_Clickobject sender EventArgs e //查询模块 string ConStr ProviderMicrosoft.Jet.OLEDB.4.0data sourceLocation.mdb//创建OleDbConnection对象 OleDbConnection con new OleDbConnectionConStr con.Open int i Convert.ToInt16textBox1 .Text OleDbCommand cmd new OleDbCommandSelect From data where IDid con cmd.Parameters.Addidi OleDbDataReader reader cmd.ExecuteReader reader.Read //textBox1.Text reader0.ToString textBox2.Text reader1.ToString textBox3.Text reader2.ToString textBox4.Text reader3.ToString textBox5.Text reader4.ToString textBox6.Text reader5.ToString textBox7.Text reader6.ToString reader.Close con.Close private void button4_Clickobject sender EventArgs e //添加 string ConStr ProviderMicrosoft.Jet.OLEDB.4.0data sourceLocation.mdb//创建OleDbConnection对象 OleDbConnection con new OleDbConnectionConStr con.Open for int i 0 i 1000 i string sql insert into dataIDvalues i OleDbCommand cmd new OleDbCommandsql con cmd.ExecuteNonQuery con.Close private void button5_Clickobject sender EventArgs e //删除 string ConStr ProviderMicrosoft.Jet.OLEDB.4.0data sourceLocation.mdb//创建OleDbConnection对象 OleDbConnection con new OleDbConnectionConStr con.Open OleDbCommand cmd new OleDbCommanddelete from data con cmd.ExecuteNonQuery private void button6_Clickobject sender EventArgs e //修改 string ConStr ProviderMicrosoft.Jet.OLEDB.4.0data sourceLocation.mdb//创建OleDbConnection对象 OleDbConnection con new OleDbConnectionConStr con.Open string sql update data set longitude12 where ID1 OleDbCommand cmd new OleDbCommandsql con cmd.ExecuteNonQuery上一篇:Java_项目开发实例_图书信息管理系统开发文档及源码