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

推荐订阅源

T
Tenable Blog
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
H
Help Net Security
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 司徒正美
量子位
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
Scott Helme
Scott Helme
The Last Watchdog
The Last Watchdog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
AI
AI
WordPress大学
WordPress大学
Security Archives - TechRepublic
Security Archives - TechRepublic
Google Online Security Blog
Google Online Security Blog
U
Unit 42
V2EX - 技术
V2EX - 技术
MongoDB | Blog
MongoDB | Blog
Schneier on Security
Schneier on Security
博客园 - Franky
H
Heimdal Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
B
Blog RSS Feed
N
News | PayPal Newsroom
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园_首页
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
雷峰网
雷峰网

博客园 - yunshu

(转帖)C/S、B/S及三层结构漫谈 TP-Link 配置(转帖) 如何用VSS VS2005重置按钮代码 asp.net 2.0 网站导航控件 WEB自定义控件小记 VS2005 DataGridView 和 GirdView 横向大比拼 web.config中连接字符串与数据库登陆方式的联系 转帖-win2003各版本的区别 您没有调试该服务器的权限,验证您是服务器“Debugger Users”组的成员 错误:未将对象引用设置到对象的实例 在绑定DataGrid控件,做添加删除时遇到问题(数组越界) visual studio.net已检测到指定的web服务器运行的不是asp.net1.1版。 request('id')语句,返回的是什么类型的数据 [WebMethod] 是什么意思? 怎样添加本地web引用 创建XML文件的两种方法 枚举类型是什么意思,怎么用? 什么是DOM?
如何在DataSet中追加记录
yunshu · 2008-04-02 · via 博客园 - yunshu

在Session里缓存这个DataTable,那么可以这样做:
首先为了方便访问,可以把DataTable做成一个属性,像这样:

public DataTable objTable
{
    get
    {
        return Session["myTable"] != null ? (DataTable)Session["myTable"] : new DataTable();
    }
    set
    {
        Session["myTable"] = value;
    }
}

之后在每次点击按钮的时候,先从Session里取出来缓存的DataTable对象,再追加,最后绑定。

private void Button1_Click(object sender, System.EventArgs e)
{   
    DataTable mydt = objTable;
   
    if(mydt.Rows.Count == 0)
    {
        mydt.Columns.Add(new DataColumn("姓名"));
        mydt.Columns.Add(new DataColumn("性别"));
    }
    DataRow mydr;
    mydr = mydt.NewRow();
    mydr[0] = TextBox1.Text.ToString();
    mydr[1] = TextBox2.Text.ToString();
    mydt.Rows.Add(mydr);

    objTable = mydt;
    dg.DataSource = mydt;
    dg.DataBind();               
}