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

推荐订阅源

B
Blog
C
Check Point Blog
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
SecWiki News
SecWiki News
有赞技术团队
有赞技术团队
Latest news
Latest news
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
Project Zero
Project Zero
H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Engineering at Meta
Engineering at Meta
T
Threat Research - Cisco Blogs
腾讯CDC
P
Proofpoint News Feed
L
LINUX DO - 热门话题
C
Cisco Blogs
P
Palo Alto Networks Blog
Vercel News
Vercel News
P
Privacy International News Feed
爱范儿
爱范儿
Scott Helme
Scott Helme
L
Lohrmann on Cybersecurity
MyScale Blog
MyScale Blog
K
Kaspersky official blog
B
Blog RSS Feed
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
O
OpenAI News
博客园 - 叶小钗
量子位
T
Tenable Blog
C
Cybersecurity and Infrastructure Security Agency CISA
J
Java Code Geeks
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hacker News: Ask HN
Hacker News: Ask HN
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
L
LINUX DO - 最新话题
F
Fortinet All Blogs
N
News | PayPal Newsroom
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 【当耐特】
N
News and Events Feed by Topic
V
Visual Studio Blog
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI

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

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)  评论()    收藏  举报