c#操作access数据库编程1

上传人:hs****ma 文档编号:412124702 上传时间:2022-11-23 格式:DOC 页数:9 大小:48KB
返回 下载 相关 举报
c#操作access数据库编程1_第1页
第1页 / 共9页
c#操作access数据库编程1_第2页
第2页 / 共9页
c#操作access数据库编程1_第3页
第3页 / 共9页
c#操作access数据库编程1_第4页
第4页 / 共9页
c#操作access数据库编程1_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《c#操作access数据库编程1》由会员分享,可在线阅读,更多相关《c#操作access数据库编程1(9页珍藏版)》请在金锄头文库上搜索。

1、c#操作 Access(上)看到CSDN上不断兄弟姐妹提问关于c#操作Access的问题,于是本人利用闲暇将c#操作Access的方法加以总结,主要解决的问题有:创建 mdb创建 table读取 table内容查询 table中的内容向 table 中插入数据删除 table 中的记录向 table 中插入照片读取 table 中的照片等。另:本人水平有限,不当之处还请斧正。废话少说,开始正题。文介绍 C#访问操作程方式创建全新的Access 数据库的基础知识,并提供一个相关的例程。ACCESS(MDB)数据库,所以还只能使用ADOX这个来自C#的还不能通过编COM的链接库来操作。主要知识点如

2、下:usingusing ;连接字符串: String connectionString = Provider= Source=;建立连接: OleDbConnection connection = new OleDbConnection(connectionString); 使用 OleDbCommand类来执行 Sql 语句:OleDbCommand cmd = new OleDbCommand(sql, connection);();();1. 创建 mdb库,例程如下:需要注意的是:参数mdbPath 是 mdb的完整路径(不包含表的名称)。例如:view plaincopy to c

3、lipboardprint建具体的表,例程如下:通常一个mdb的可以包含n 个表。下面的程序主要是创建一个table 。view plaincopy to clipboardprintoString();alue = false;500);oString();alue = false;500);取 mdb内容(完全读取) ,例程如下:本例程返回的是一个 DataTable ,如需其他格式可以自行转换。view plaincopy to clipboardprintoString();oString();取 mdb内容(按列读取) ,例程如下:columns 数组存储的是你要查询的列名称(必须确

4、保mdb表中存在你要的列)view plaincopy to clipboardprintoString() + ,;strColumn = (,);= select +strColumn+ from + tableName; oString();oString() + ,;strColumn = (,);= select +strColumn+ from + tableName;oString();oktable了),其中的中插入数据(按行插入,如果需要插入多条请自己组织这个函数就insertArray存储的是一系列Node, pictureNode是 PictureNode 。view p

5、laincopy to clipboardprint新一行的数据(与插入类似)view plaincopy to clipboardprint插入图片数据.view plaincopy to clipboardprintalue = pic;();();return true;catch (Exception err)errinfo = ;return false;alue = pic;();();return true;catch (Exception err)errinfo = ;return false;4. 修改 mdb的一条数据 .view plaincopy to clipboar

6、dprintmdb中获得照片view plaincopy to clipboardprintdb;private dataGrid1;private DataSet ds = null;public Form1()InitializeComponent();private void Form1_Load(object sender, EventArgs e)();con = new OleDbConnection(sqlstring);getData();oString();= dr1.ToString();catch (Exception ex);finally();private void

7、 button1_Click(object sender, EventArgs e)Form2 f = new Form2;();在 C#中使用控件 DataGridView 实现数据库增删改查using System;usingusing ;using ;usingusing ;using ;using DataSourcepublic partial class Form1 : Formpublic Form1()InitializeComponent();private DataSet ds = new DataSet();private SqlConnection conn = nul

8、l;private SqlDataAdapter da = null;private const string DRIVER =server=.;database=northwind;uid=sa;pwd=sa;private const string sql_select = select * fromregion;private void Form1_Load(object sender, EventArgs e)conn = new SqlConnection(DRIVER);da = new SqlDataAdapter(sql_select,conn);(ds,table);=tab

9、le.DefaultView;private bool BtnInsert() owsint count = (ds);bool result = count 0 true : false;return result;private void button2_Click(object sender, EventArgs e)if ().;oString();if (mcount 0)elected = true;= .Cells;ndex;ellsj.() + ,;ResumeAddOrUpdate resumeAdd = new ResumeAddOrUpdate(str,this);(Up

10、date);= ;quals(save)= true;= false;else if().Equals(update)= false;= true;= false;quals(男)= true;else if (content1.Equals(女)= true;= content2.ToString();= content3.ToString();= content4.ToString();= content5.ToString();= content6.ToString();= content7.ToString();= content8.ToString();= content9.ToSt

11、ring();= content10.ToString();string strPictrueBox = getStrOfPictureBox pg);ndex;ells0.().Trim();elected = true;= .Cells;C# WinForm 实现增删改查等功能(Access 版)系列之五 - 查询查询 记录模块设计与实现oString().Equals(0) & reader0.ToString()!= & reader0.ToString()!=null)strpictrue = reader0.ToString();elsestrpictrue = + Image;/*DataTable dt = new DataTable();OleDbDataAdapter oda = new OleDbDataAdapter(sqlText, conn);(dt);= dt;*/catch (Exception ex)();finally

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号