惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
爱范儿
爱范儿
Attack and Defense Labs
Attack and Defense Labs
量子位
The GitHub Blog
The GitHub Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Scott Helme
Scott Helme
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 叶小钗
C
Cybersecurity and Infrastructure Security Agency CISA
S
Securelist
S
Schneier on Security
C
Cisco Blogs
B
Blog RSS Feed
Cisco Talos Blog
Cisco Talos Blog
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
腾讯CDC
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
Y
Y Combinator Blog
Latest news
Latest news
T
Tailwind CSS Blog
Jina AI
Jina AI
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
C
CERT Recently Published Vulnerability Notes
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
Lohrmann on Cybersecurity
The Cloudflare Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Security Blog
Microsoft Security Blog
H
Help Net Security
P
Palo Alto Networks Blog
V
V2EX
博客园_首页
D
Docker
T
Threat Research - Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Vulnerabilities – Threatpost
月光博客
月光博客
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Know Your Adversary
Know Your Adversary
L
LangChain Blog
The Hacker News
The Hacker News
K
Kaspersky official blog
The Register - Security
The Register - Security
NISL@THU
NISL@THU

博客园 - 木人(我现在不是老大)

ERP系统的专业化发展趋势 讨厌的real和float数据 Svcutil使用点滴 windows server2003企业版64位安装sql server2008企业版64位 读书笔记 UltraGrid(16) 水晶报表使用push模式(2) 水晶报表使用push模式(1) SQL SERVER2000存储过程调试 读书笔记 UltraGrid(15) 读书笔记 UltraGrid(14) 读书笔记 UltraGrid(12) 读书笔记 UltraGrid(11) 读书笔记 UltraGrid(10) 读书笔记 UltraGrid(8) 读书笔记 UltraGrid(7) 读书笔记 UltraGrid(6) 读书笔记 UltraGrid(5) 读书笔记 UltraGrid(4) 读书笔记 UltraGrid(3)
读书笔记 UltraGrid(9)
木人(我现在不是老大) · 2012-02-11 · via 博客园 - 木人(我现在不是老大)

关于SqlDataAdapter填充数据
1. SqlDataAdapter da = new SqlDataAdapter("select * from customers", cnnstring);
da.Fill(data);
如果不指名源表名,则缺省为Table;
2.public int Fill(DataSet dataSet,string srcTable)用于表映射的源表的名称。
da.Fill(data,"客户");
指定原表名为"客户",填充后datatable的名称也为"客户",这点有点奇怪呢。
3.使用TableMapping
SqlDataAdapter da = new SqlDataAdapter("select * from customers", cnnstring);
da.TableMappings.Add("customers", "客户");
da.Fill(data, "customers");

da = new SqlDataAdapter("select * from pdctorders;", cnnstring);
da.TableMappings.Add("PdctOrders", "订单");
da.Fill(data, "PdctOrders");
         
da = new SqlDataAdapter("select * from SaleContracts", cnnstring);
da.TableMappings.Add("SaleContracts", "合同");
da.Fill(data, "SaleContracts");
这样指定了源表和datatable的对应关系,这样填充后相应的datatable表名分别为"客户"、"订单"和"合同"。
4.实际上有更简单的写法
SqlDataAdapter da = new SqlDataAdapter("select * from customers;select * from pdctorders;select * from SaleContracts;", cnnstring);
da.TableMappings.Add("Table", "客户");
da.TableMappings.Add("Table1", "订单");
da.TableMappings.Add("Table2", "合同");
da.Fill(data);
注意Table\Table1\Table2的写法
5:建立关系
DataRelation mydr = new DataRelation("Customers_PdctOrders", data.Tables["客户"].Columns["CustID"], data.Tables["订单"].Columns["CustID"], false);
data.Relations.Add(mydr);
DataRelation mydr2 = new DataRelation("Customers_SaleContracts", data.Tables["客户"].Columns["CustID"], data.Tables["合同"].Columns["CustID"], false);
data.Relations.Add(mydr2);
这样this.ultraGrid1.DataSource = data;
绑定数据后即可以层次关系体现了。

posted on 2012-02-11 23:30  木人(我现在不是老大)  阅读(272)  评论()    收藏  举报