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]); } } }
最新文章
- 二模 (13)day2
- 黄聪:C#操作Word表格的常见操作(转)
- Spring 依赖注入的方式
- 大型网站系统架构演化之路【mark】
- Java Collections Source Code Series 1 --- 简介
- 宠物AI(个人觉得有问题)
- Windows 之 CMD命令
- yii2单独给input或者其他标签定义class
- uva 1030 - Image Is Everything(迭代更新)
- memcache 操作类
- Linux服务器SNMP常用OID (转)
- 针对IE的CSS样式hack
- 扩展entity framework core 实现默认字符串长度,decimal精度,entity自动注册和配置
- Java线程面试题
- Python 基础【二】 下
- ES6 迭代器和生成器
- [tldk][dpdk][dev] TLDK--基于dpdk的用户态协议栈传输层组件简单调研
- SpringMVC中@RestController的用法
- 【Linux】find命令
- C++:sprintf()的用法(转)
热门文章
- Android Studio环境解读
- 基于JWT的无状态分布式授权【本文摘自智车芯官网】
- CSS position属性---absolute与relative
- 使用 window.getSelection() 方法获取鼠标划取部分的起始位置和结束位置的问题(高亮后不能正确获取)
- Hangman游戏源代码 --- python实现
- 【AtCoder ARC076】F Exhausted? 霍尔定理+线段树
- Antlr 在 idea 中正确使用的方式
- [BZOJ1921] [CTSC2010]珠宝商
- [CF327E]Axis Walking([洛谷P2396]yyy loves Maths VII)
- jocky1.0.3 (原joc) java混淆器 去除jdk版本限制