欢迎来到天天文库
浏览记录
ID:21143986
大小:38.00 KB
页数:3页
时间:2018-10-19
《c#操作access的查询、添加、删除、修改源程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Data.Common;usingSystem.Drawing;usingSystem.Linq;usingSystem.Data.OleDb;usingSystem.Text;usingSystem.Windows.Forms;namespaceLocation{publicpartialclassForm1:Form{publicForm1(){InitializeComponent(
2、);}privatevoidForm1_Load(objectsender,EventArgse){this.Text="LocationSystem";button1.Text="连接数据库";button2.Text="查询";button3.Text="退出";button4.Text="添加";button5.Text="删除";button6.Text="修改";label1.Text="ID:";textBox1.Text="0";}privatevoidbutton1_Click(objectsender,EventArgse){stringConStr="Provide
3、r=Microsoft.Jet.OLEDB.4.0;datasource=Location.mdb";//创建OleDbConnection对象OleDbConnectioncon=newOleDbConnection(ConStr);con.Open();if(con.State==ConnectionState.Open){MessageBox.Show("Access数据库的连接成功!","Access数据库的连接");}else{MessageBox.Show("Access数据库的连接失败!","Access数据库的连接");}con.Close();}privatevoid
4、button3_Click(objectsender,EventArgse)//退出{this.Close();}privatevoidbutton2_Click(objectsender,EventArgse)//查询模块{stringConStr="Provider=Microsoft.Jet.OLEDB.4.0;datasource=Location.mdb";//创建OleDbConnection对象OleDbConnectioncon=newOleDbConnection(ConStr);con.Open();inti=Convert.ToInt16(textBox1.Tex
5、t);OleDbCommandcmd=newOleDbCommand("Select*FromdatawhereID>=@id",con);cmd.Parameters.Add("@id",i);OleDbDataReaderreader=cmd.ExecuteReader();reader.Read();//textBox1.Text=reader[0].ToString();textBox2.Text=reader[1].ToString();textBox3.Text=reader[2].ToString();textBox4.Text=reader[3].ToString();
6、textBox5.Text=reader[4].ToString();textBox6.Text=reader[5].ToString();textBox7.Text=reader[6].ToString();reader.Close();con.Close();}privatevoidbutton4_Click(objectsender,EventArgse)//添加{stringConStr="Provider=Microsoft.Jet.OLEDB.4.0;datasource=Location.mdb";//创建OleDbConnection对象OleDbConnectionc
7、on=newOleDbConnection(ConStr);con.Open();for(inti=0;i<1000;i++){stringsql="insertintodata(ID)values("+i+")";OleDbCommandcmd=newOleDbCommand(sql,con);cmd.ExecuteNonQuery();}con.Close();}privatevoidbutton5_Click(objectsender,E
此文档下载收益归作者所有