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]); } } }
相关文章
- 在VS中让一个JS文件智能提示另一个JS文件中的成员2--具体引用
- < %=...%>< %#... %>< % %>< %@ %>具体意义
- 在XML里的XSD和DTD以及standalone的使用3----具体使用详解
- 没提供编码格式,读文件时要怎么推测文件具体的编码
- 基于机器学习人脸识别face recognition具体的算法和原理
- EasyNVR智能云终端硬件使用说明(EasyNVR无插件直播服务硬件的具体使用方法)
- 移动端h5网页、微信网页调试之利用vConsole真机调试+显示控制台打印信息、调试接口(附带vue项目里的具体使用方法)
- Python之sklearn:LabelEncoder函数简介(编码与编码还原)、使用方法、具体案例(在数据缺失和test数据内存在新值(train数据未出现过)环境下的数据LE化)之详细攻略
- Python之pandas:pandas中数据处理常用函数(与空值相关/去重和替代)简介、具体案例、使用方法之详细攻略
- Python之Pandas:pandas.DataFrame.to_csv函数的简介、具体案例、使用方法详细攻略
- java - @Async 具体使用
- 细谈 == 和 equals 的具体区别 【包括equals源码分析】
- 算法基础(八):超具体最优二叉树构建(1)
- SNMP协议具体解释
- git使用具体介绍
- PHP PDO函数库具体解释
- Android-BroadcastReceiver具体解释
- malloc功能具体解释
- FileSystemWatcher使用方法具体解释
- 分形树Fractal tree介绍——具体如何结合TokuDB还没有太懂,先记住其和LSM都是一样的适合写密集
- vue-tour快速入门:VUE项目中如何使用vue-tour新手引导指引插件?怎样使用?包含具体实例