• 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:VS2015ProgrammingMyTestTestUDLTextFile1.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:VS2015ProgrammingMyTestTestUDLTextFile1.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]);         }     } }

  • 相关阅读:
    【UOJ #268】【清华集训2016】数据交互(动态DP)
    【UOJ #267】【清华集训2016】魔法小程序(前缀和)
    【UOJ #266】【清华集训2016】Alice和Bob又在玩游戏(SG函数+01Trie)
    【CSP-S 2019题解】
    【CSP 2019游记】
    【CSP-S 2019模拟题解】
    sql语句: update和sql函数的冲突
    http协议之实践巩固(深度篇一)
    不错的开发工具做下记录
    javascrpt之this指向问题
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/6866174.html
Copyright © 2020-2023  润新知