OleDbDataAdapter具体使用

网友投稿 536 2022-09-26

OleDbDataAdapter具体使用

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]); } } }

龙腾一族至尊龙骑

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:域名里的知识点
下一篇:数位dp详解
相关文章

 发表评论

暂时没有评论,来抢沙发吧~