OleDbDataAdapter具体使用

OleDbDataAdapter具体使用usingSystem usingSystem Collections Generic usingSystem ComponentMod usingSystem Data usingSystem Data OleDb usingSystem Data SqlClient usingSystem Drawing usingSystem Linq usingSys

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/231544.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • winzip15.0注冊码

    winzip15.0注冊码

    2021年12月6日
    59
  • ubuntu安装图形化界面_ubuntu 安装桌面

    ubuntu安装图形化界面_ubuntu 安装桌面系统安装的Ubuntu16.04,默认的桌面的系统不是很习惯,特意安装了xfce4桌面系统。设置开机启动项从Xfce桌面菜单中选择"SettingsManager"(设置管理器)->Settings"(设置)窗口->SessionandStartup"(会话和启动)图标。1各种桌面环境下设置开机自启动应用程序的方法↩︎…

    2025年7月2日
    1
  • 快速搭建一个自己的服务器详解(java环境)「建议收藏」

    快速搭建一个自己的服务器详解(java环境)「建议收藏」一.服务器的购买1.我选择的是阿里云的服务器,学生价9.5元一个月,百度直接搜索阿里云,然后点击右上角登录,推荐大家用支付宝扫码登录,方便快捷。阿里云官网的东西比较多,登录后我找了很久也没有找到学生服务器在哪里卖,最后在咨询里找到了这个网址,https://promotion.aliyun.com/ntms/campus2017.html,购买的时候需要进行学生认证,按照他的要求一步步…

    2022年6月11日
    25
  • java的编程思想是什么’_编程思想 是什么

    java的编程思想是什么’_编程思想 是什么未完待续,预计4.4完成1什么是项目在既定的资源和要求的约束下,为实现某种目的而相互联系的一次性工作任务。项目可以创造:1.一个产品;2.一种服务或提供服务的能力;3.对现有产品线或服务的改进;4.一种成果。项目的两大特性:1.临时性(Temporary)项目有明确的起点和终点,临时性并不意味着持续时间短,很多项目的结果具有持久性2.独特性(Unique)项目创造独特的可交互成果(Deliver…

    2022年7月8日
    20
  • python—whl文件介绍与安装

    python—whl文件介绍与安装在安装whl文件之前,我们需要先搞清楚什么是whl文件,whl格式本质上是一个压缩包,里面包含了py文件,以及经过编译的pyd文件。使得可以在不具备编译环境的情况下,选择合适自己的python环境进行安装。在Win7下安装whl文件,可以直接使用pip命令:pipinstallMySQL_python-1.2.5-cp36-none-win32.whl(1)虽然大多数情况下,…

    2022年5月30日
    83
  • 二叉树的建立及其递归遍历(C语言实现)

    二叉树的建立及其递归遍历(C语言实现)最近在学习数据结构中树的概念,迟迟不得入门,应该是自己的懒惰和没有勤加练习导致的,以后应该多加练习以下是我对二叉树的一些总结内容二叉树的特点有:-每一个节点最多有两棵子树,所以二叉树中不存在度大于2的节点,注意,是最多有两棵,没有也是可以的左子树和右子树是有顺序的,次序不能颠倒,这点可以在哈夫曼编码中体现,顺序不同编码方式不同-即使树中某个节点中只有一个子树的花,也要区分它…

    2022年4月28日
    81

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号