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具体使用的更多相关文章

  1. C#使用DataSet类、DataTable类、DataRow类、OleDbConnection类、OleDbDataAdapter类编写简单数据库应用

    //注意:请使用VS2010打开以下的源代码. //源代码地址:http://pan.baidu.com/s/1j9WVR using System; using System.Collections ...

  2. 怎样用OleDbDataAdapter来对数据库进行操作?

      请问怎样用OleDbDataAdapter来对数据库进行删除.改动和加入? OleDbDataAdapter是DataSet和数据源之间建立联系的重要纽带.用它我们能够对数据库进行删除.改动和加入 ...

  3. 【c#操作office】--OleDbDataAdapter 与OleDbDataReader方式读取excel,并转换为datatable

    OleDbDataAdapter方式: /// <summary> /// 读取excel的表格放到DataTable中 ---OleDbDataAdapter /// </summ ...

  4. OleDbDataAdapter具体使用11

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. 如何在不使用OleDbCommandBuilder情况下使用OleDbDataAdapter更新Access数据库记录

    我在博客园的博问和微软论坛都曾经请教了这个问题(问题链接),可能我的问题太简单,并没有获得太多解答. 到今天为止,我自己通过查找和摸索,基本把这个问题解决了,还是记录下来,供其他朋友参考. 第一次解决 ...

  6. oledbdataadapter 读取excel数据时,有的单元格内容不能读出

    表现:excel中某列中,有的单元格左上角有绿色箭头标志,有的没有,c#编写读取程序,但是只能读取出带绿色箭头的单元格中的内容,其余不带的读取不到内容 原因:excel中单元格因为是文本格式而存储了数 ...

  7. 【基于WinForm+Access局域网共享数据库的项目总结】之篇一:WinForm开发总体概述与技术实现

    篇一:WinForm开发总体概述与技术实现 篇二:WinForm开发扇形图统计和Excel数据导出 篇三:Access远程连接数据库和窗体打包部署 [小记]:最近基于WinForm+Access数据库 ...

  8. DevExpress - 使用 GaugeControl 标尺组件制作抽奖程序 附源码

    前不久,公司举办了15周年庆,其中添加了一个抽奖环节,要从在读学员中随机抽取幸运学员,当然,这个任务就分到了我这里. 最后的效果如下,启动有个欢迎页面,数据是来自Excel的,点击开始则上面的学号及姓 ...

  9. C#/ASP.NET完善的DBHelper,配套Model生成器

    支持Oracle.MSSQL.MySQL.SQLite四种数据库,支持事务,支持对象关系映射:已在多个项目中实际使用. 没有语法糖,学习成本几乎为0,拿来即用. DBHelper类完整代码: usin ...

随机推荐

  1. 数据结构-排序-shell排序

    shell排序 首先,希尔排序适用于待排序列关键有序. 接下来一步步图解SHELL排序 我为了方便理解内部操作.我先把代码输出整理下. #include<iostream> #includ ...

  2. Java开发JDBC连接数据库

    Java开发JDBC连接数据库 创建一个以JDBC连接数据库的程序,包含6个步骤: JDBC五部曲1.加载驱动2.获得链接3.获取statement对象 4.执行SQL语句5.产生resultset对 ...

  3. URAL 1932 The Secret of Identifier(容斥)

    Description Davy Jones: You've been captain of the Black Pearl for 13 years. That was our agreement. ...

  4. WIN8/8.1/10换系统常见的几个问题

    1.如果高级选项中没有UEFI固件设置,这该怎么进入BIOS呢? 答:还有一种方法是,首先关闭快速启动,然后重启,开机画面出来之后按F1,F2,F12,delete,总有一个是对的(不确定的话可以四个 ...

  5. PAT 1015 德才论

    https://pintia.cn/problem-sets/994805260223102976/problems/994805307551629312 宋代史学家司马光在<资治通鉴>中 ...

  6. Chrome Extension & Dark Theme

    Chrome Extension & Dark Theme https://chrome.google.com/webstore/detail/eimadpbcbfnmbkopoojfekhn ...

  7. Splunk学习与实践

      一.  Splunk公司与产品 美国Splunk公司,成立于2004年,2012年纳斯达克上市,第一家大数据上市公司,荣获众多奖项和殊荣.总部位于美国旧金山,伦敦为国际总部,香港设有亚太支持中心, ...

  8. Tomcat-Jdbc-Pool连接池参数说明

    原文  http://liuxing.info/2016/01/05/Tomcat-Jdbc-Pool参数说明/ 转载收藏用,如有侵权,请联系删除,谢谢. 介绍 Tomcat 在 7.0 以前的版本都 ...

  9. wyh的物品~(二分)

    链接:https://www.nowcoder.com/acm/contest/93/I来源:牛客网 题目描述 wyh学长现在手里有n个物品,这n个物品的重量和价值都告诉你,然后现在让你从中选取k个, ...

  10. 修改centos的源

    最近都在使用国内的VPS.系统统一使用的都是Linux系统.但是,有一些服务商的系统给默认设置的是国外的.这样就会导致下载速度缓慢.于是,找到了国内几家比较热门的镜像点.奉献给大家.下面的镜像全部支持 ...