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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
W
WeLiveSecurity
O
OpenAI News
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Webroot Blog
Webroot Blog
Google Online Security Blog
Google Online Security Blog
云风的 BLOG
云风的 BLOG
N
News | PayPal Newsroom
H
Hacker News: Front Page
博客园_首页
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The Last Watchdog
The Last Watchdog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Heimdal Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Schneier on Security
宝玉的分享
宝玉的分享
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
Microsoft Security Blog
Microsoft Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
GbyAI
GbyAI
Cloudbric
Cloudbric
TaoSecurity Blog
TaoSecurity Blog
人人都是产品经理
人人都是产品经理
P
Palo Alto Networks Blog
M
MIT News - Artificial intelligence
G
GRAHAM CLULEY
C
Check Point Blog
Apple Machine Learning Research
Apple Machine Learning Research
Last Week in AI
Last Week in AI
T
Troy Hunt's Blog
L
Lohrmann on Cybersecurity
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
量子位
博客园 - 聂微东
S
Securelist
博客园 - 三生石上(FineUI控件)
F
Full Disclosure
G
Google Developers Blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
AI
AI
PCI Perspectives
PCI Perspectives

博客园 - 小子好黑

String 和 string vs2005常用快捷键 菜单 Wscript.shell 收集一些常用的正则表达式 WINDOWS自启动方式总结 简单的C#面试题 写卡程序 C#后台调用JS Request.ServerVariables获取环境变量 文本框回车自动提交FORM的解决方法 闲来无事,JS排序 sql 查询数据生成insert语句 学习.NET的经典网站 查询系统所有存储过程,并以树形结构显示 html实现树形结构(精简代码) c# 字母大小写转换 对于错误“不能确定应用到此机器的组策略安全性设置”的解决办法
直接创建一个DataTable,并为之添加数据(自定义DataTable)
小子好黑 · 2007-10-23 · via 博客园 - 小子好黑

DataTable dt=new DataTable("cart");
   DataColumn dc1
=new DataColumn("prizename",Type.GetType("System.String"));
   DataColumn dc2
=new DataColumn("point",Type.GetType("System.Int16"));
   DataColumn dc3
=new DataColumn("number",Type.GetType("System.Int16"));
   DataColumn dc4
=new DataColumn("totalpoint",Type.GetType("System.Int64"));
   DataColumn dc5
=new DataColumn("prizeid",Type.GetType("System.String"));
   dt.Columns.Add(dc1);
   dt.Columns.Add(dc2);
   dt.Columns.Add(dc3);
   dt.Columns.Add(dc4);
   dt.Columns.Add(dc5);
//以上代码完成了DataTable的构架,但是里面是没有任何数据的
   for(int i=0;i<10;i++)
   
{
    DataRow dr
=dt.NewRow();
    dr[
"prizename"]="娃娃";
    dr[
"point"]=10;
    dr[
"number"]=1;
    dr[
"totalpoint"]=10;
    dr[
"prizeid"]="001";
    dt.Rows.Add(dr);
   }

//填充了10条相同的记录进去

有人会这么做
DataRow dr
=new DataRow();
  ..
dt.Rows.Add(dr);
这样是不行的,因为一个DataRow必定是属于一个DataTable的,不能凭空建立,就好比一条记录一定是属于一个表一样

又有人这么做
    DataRow dr
=dt.NewRow();
    dr[
"prizename"]="娃娃";
    dr[
"point"]=10;
    dr[
"number"]=1;
    dr[
"totalpoint"]=10;
    dr[
"prizeid"]="001";
   
for(int i=0;i<10;i++)
   
{
         dt.Rows.Add(dr);
   }

这样做同样是错误的,因为DataTable已经有这条DataRow了,就好比一个表中不可能存在2条一样的记录,必须每次NewRow()