zoukankan
html css js c++ java
DataAdapter数据集DataSet和数据库的同步(3):使用CommandBuilder来更新数据集
/**/
/*
--===------------------------------------------===---
CommandBuilder:
如果DataTable映射到单个数据库表或者从单个数据库表生成,
可以利用CommandBuilder对象自动生成DataAdapter的3个命令:
DeleteCommand, UpdateCommand, InsertCommand.
为了生成Insert,Update,Delete语句,CommandBuilder会自动
使用SelectCommand属性来检索所需的元数据集.
SelectComandText里面必须要有主键字段,否则无法Builder~!
许明会 2007年12月22日 23:24:25
--===------------------------------------------===---
*/
using
System;
using
System.Data;
using
System.Data.SqlClient;
namespace
xumh
{
public
class
runMyApp
{
static
void
ShowTable(DataTable dataTable)
{
foreach
(DataRow row
in
dataTable.Rows)
{
for
(
int
i
=
0
;i
<
dataTable.Columns.Count; i
++
)
Console.Write(
"
{0}\t
"
,row[i]);
Console.WriteLine();
}
}
static
void
Main()
{
SqlConnection cn
=
new
SqlConnection(
@"
server=.; database=northwind; integrated security=true
"
);
//
显示原始数据
SqlDataAdapter da
=
new
SqlDataAdapter(
"
select employeeid,firstname,lastname,title from employees
"
,cn);
DataSet dsEmployees
=
new
DataSet();
da.Fill(dsEmployees);
ShowTable(dsEmployees.Tables[
0
]);
//
更改数据
Console.ReadLine();
dsEmployees.Tables[
0
].Rows[
0
][
"
FirstName
"
]
=
"
Nancy
"
;
//
XuMinghui
SqlCommandBuilder builder
=
new
SqlCommandBuilder(da);
//
SqlCommandBuilder
//
Console.WriteLine(da.UpdateCommand.CommandText);
//
查看自动生成的CommandText
da.Update(dsEmployees);
ShowTable(dsEmployees.Tables[
0
]);
}
}
;
}
查看全文
相关阅读:
MySQL之事务
TP5之查询那些事
TP5之上传多张图片
PhpStorm之设置字体大小
Git入门
TP5之自定义分页样式
TP之安全机制
Navicat Premium连接服务器数据库
IEnumerable 与 IEnumerable<T>
关于递归
原文地址:https://www.cnblogs.com/flaaash/p/1011128.html
最新文章
golang bitmap(位图)
什么是IO
Redis为什么是单线程?为什么有如此高的性能?
更换yum源的步骤
Django资源大全
正规的运维工作是什么的?
liunx下添加新硬盘的全过程
linux命令大全
关于apt-get命令介绍及其参数使用
yum命令相关的参数及作用
热门文章
systemctl管理服务的相关命令
Centos7安装Docker最新版
linux系统中的主目录结构及其作用
TP5实现签到功能
html扩展调用qq邮箱
html扩展调用qq聊天窗口
初识 python
python 之 配置环境变量、通过pip 安装第三方库
composer下载tp5第三方扩展
TP5之model
Copyright © 2011-2022 走看看