c#操作access的查询、添加、删除、修改源程序

c#操作access的查询、添加、删除、修改源程序

ID:21143986

大小:38.00 KB

页数:3页

时间:2018-10-19

c#操作access的查询、添加、删除、修改源程序_第1页
c#操作access的查询、添加、删除、修改源程序_第2页
c#操作access的查询、添加、删除、修改源程序_第3页
资源描述:

《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

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。