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
]);
}
}
;
}
查看全文
相关阅读:
使用公钥登录SSL
javascript看你能够做对几题
windows 与fedora时间差
Linux 启动直接进入 console,
fedora -- java多版本切换
fedora 解决yumBackend.py进程CPU占用过高
fedora 禁止nouveau加载
联邦学习中的隐私研究
优秀博客链接
【论文学习11】GIANT: Globally Improved Approximate Newton Method for Distributed Optimization
原文地址:https://www.cnblogs.com/flaaash/p/1011128.html
最新文章
CentOS7.X安装Python3
CentOS7.X安装Nginx
MySQL 开启远程连接
CentOS7 firewall开放3306端口
CentOS安装rpm包出现冲突时的解决办法
CentOS安装rpm包时遇到头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY时的解决办法
ubuntu 设置显示器的亮度
ubuntu安装oracle java
PIL 安装
fedora gnome extension
热门文章
linux -- 启动时启动服务或者执行命令
git 基本操作
rabbitmq安装
fedora 20 PIL
在fedora 桌面上添加应用程序
fedora安装postgresql
Fedora 命令
fedora 安装chrome
fedroa 更换字体
fedora 取消自动升级
Copyright © 2011-2022 走看看