OleDbDataAdapter具体使用
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
namespace TestUDL { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
OleDbDataAdapter ad; DataSet ds; public void fanfa() { //string connectString = "Data Source=localhost;Initial Catalog=MytestDB;Integrated Security=SSPI"; //SqlConnection sqlConnect = new SqlConnection(connectString); string connectString = @"File Name=D:\VS2015Programming\MyTest\TestUDL\TextFile1.udl;"; OleDbConnection conn = new OleDbConnection(connectString); conn.Open(); OleDbCommand sqlCommand = conn.CreateCommand(); string sqlCommandText = "SELECT [ID],[Name] FROM[MytestDB].[dbo].[PersonTable]"; sqlCommand.CommandText = sqlCommandText; //OleDbDataReader sqlDataReader = sqlCommand.ExecuteReader(); ad = new OleDbDataAdapter(sqlCommand); OleDbCommandBuilder bb = new OleDbCommandBuilder(ad); ad.UpdateCommand = bb.GetUpdateCommand(); ad.InsertCommand = bb.GetInsertCommand(); ad.DeleteCommand = bb.GetDeleteCommand(); ds = new DataSet(); ad.Fill(ds); } private void button1_Click(object sender, EventArgs e) { ////string connectString = "Data Source=localhost;Initial Catalog=MytestDB;Integrated Security=SSPI"; ////SqlConnection sqlConnect = new SqlConnection(connectString); //string connectString = @"File Name=D:\VS2015Programming\MyTest\TestUDL\TextFile1.udl;"; //OleDbConnection conn = new OleDbConnection(connectString); //conn.Open(); //OleDbCommand sqlCommand = conn.CreateCommand(); //string sqlCommandText = "SELECT [ID],[Name] FROM[MytestDB].[dbo].[PersonTable]"; //sqlCommand.CommandText = sqlCommandText; ////OleDbDataReader sqlDataReader = sqlCommand.ExecuteReader(); //OleDbDataAdapter ad = new OleDbDataAdapter(sqlCommand); //DataSet ds = new DataSet(); //ad.Fill(ds); fanfa(); this.dataGridView1.DataSource = ds.Tables[0]; }
private void button2_Click(object sender, EventArgs e) { DataTableCollection ss = ds.Tables; //ds.Tables[0].Rows[5].RowState = DataRowState.Added; this.ad.Update(ds.Tables[0]); } } }
OleDbDataAdapter具体使用的更多相关文章
- C#使用DataSet类、DataTable类、DataRow类、OleDbConnection类、OleDbDataAdapter类编写简单数据库应用
//注意:请使用VS2010打开以下的源代码. //源代码地址:http://pan.baidu.com/s/1j9WVR using System; using System.Collections ...
- 怎样用OleDbDataAdapter来对数据库进行操作?
请问怎样用OleDbDataAdapter来对数据库进行删除.改动和加入? OleDbDataAdapter是DataSet和数据源之间建立联系的重要纽带.用它我们能够对数据库进行删除.改动和加入 ...
- 【c#操作office】--OleDbDataAdapter 与OleDbDataReader方式读取excel,并转换为datatable
OleDbDataAdapter方式: /// <summary> /// 读取excel的表格放到DataTable中 ---OleDbDataAdapter /// </summ ...
- OleDbDataAdapter具体使用11
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 如何在不使用OleDbCommandBuilder情况下使用OleDbDataAdapter更新Access数据库记录
我在博客园的博问和微软论坛都曾经请教了这个问题(问题链接),可能我的问题太简单,并没有获得太多解答. 到今天为止,我自己通过查找和摸索,基本把这个问题解决了,还是记录下来,供其他朋友参考. 第一次解决 ...
- oledbdataadapter 读取excel数据时,有的单元格内容不能读出
表现:excel中某列中,有的单元格左上角有绿色箭头标志,有的没有,c#编写读取程序,但是只能读取出带绿色箭头的单元格中的内容,其余不带的读取不到内容 原因:excel中单元格因为是文本格式而存储了数 ...
- 【基于WinForm+Access局域网共享数据库的项目总结】之篇一:WinForm开发总体概述与技术实现
篇一:WinForm开发总体概述与技术实现 篇二:WinForm开发扇形图统计和Excel数据导出 篇三:Access远程连接数据库和窗体打包部署 [小记]:最近基于WinForm+Access数据库 ...
- DevExpress - 使用 GaugeControl 标尺组件制作抽奖程序 附源码
前不久,公司举办了15周年庆,其中添加了一个抽奖环节,要从在读学员中随机抽取幸运学员,当然,这个任务就分到了我这里. 最后的效果如下,启动有个欢迎页面,数据是来自Excel的,点击开始则上面的学号及姓 ...
- C#/ASP.NET完善的DBHelper,配套Model生成器
支持Oracle.MSSQL.MySQL.SQLite四种数据库,支持事务,支持对象关系映射:已在多个项目中实际使用. 没有语法糖,学习成本几乎为0,拿来即用. DBHelper类完整代码: usin ...
随机推荐
- 并查集——hdu1213(入门)
传送门:How Many Tables 模板代入 判断几个连通分支 DFS亦可完成 [并查集] #include <iostream> #include <cstdio> #i ...
- poj1789 Truck History最小生成树
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20768 Accepted: 8045 De ...
- WEB-INF目录
背景: 在项目中,使用 "${pageContext.request.contextPath}/image/01.jpg"获取不到该图片.在浏览器中直接输入地址也找不到,报错404 ...
- jsp实用过滤器写法
使用过滤器来给servlet设置编码 public class CharacterEncodingFilter implements Filter{ @Override public void des ...
- 判断腾讯QQ是否在线
http://webpresence.qq.com/getonline?Type=1&1617052138: 判断腾讯QQ是否在线接口. 下面是个简单的例子: <!doctype htm ...
- hdu 1285 确定比赛名次 (拓扑)
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- JDBC连接数据库的过程
以连接MySQL为例: (1)加载MySQL数据库连接的驱动程序.到MySQL官网下载该驱动程序jar包,然后把包复制到WEB-INF/lib目录下,则JDBC会调用Class.forName()方法 ...
- [POI2007]ATR-Tourist Attractions
题目大意:一个无向图,从$1$到$n$,要求必须经过$2,3,\dots,k+1$,给出一些限制关系,要求在经过$v\leq k+1$之前必须经过$u\leq k+1$,求最短路 题解:预处理出$1\ ...
- 支持jsonP的Controller写法
支持jsonP的Controller写法 package com.taotao.sso.controller; import org.apache.commons.lang3.StringUtils; ...
- Maven如何打包本地依赖包
有的jar包,在maven中心库里面是没有的,那么,如何在项目中使用呢? 假设我们需要使用:apache-ant-zip-2.3.jar 将该jar包,放在项目的lib目录,例如: 在pom.xml里 ...