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
]);
}
}
;
}
查看全文
相关阅读:
No enclosing instance of type XXX is accessible.
No enclosing instance of type XXX is accessible.
Websphere 学习(一)
List去重与equals/hashcode
List去重与equals/hashcode
org.apache.log4j.Logger详解
org.apache.log4j.Logger详解
onclick="return checkForm()" 、onclick="checkForm();return false;"解析 与 return false;
onclick="return checkForm()" 、onclick="checkForm();return false;"解析 与 return false;
大数据基础第一天内容
原文地址:https://www.cnblogs.com/flaaash/p/1011128.html
最新文章
python语言程序设计7
python语言程序设计6
python语言程序设计5
python语言程序设计3
centos7使用firewalld打开关闭防火墙和端口
CentOS7.3环境配置Java和tomcat启动
CentOS从下载到安装
for循环和字典预习
10月23日——作业1——while循环练习
命令行安装KVM
热门文章
virsh命令
kvm安装
mysql主从切换
python函数
python深浅拷贝
python中的循环
python表达式
python基础数据类型
这个问题有没有什么简单的方法呢?
Websphere 学习(二)
Copyright © 2011-2022 走看看