向数据集添加行 [英] Adding rows to dataset

查看:98
本文介绍了向数据集添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建手动填充的 DataSet ?即。填写代码或通过用户输入。如果要先创建 DataTable DataRow ,我想知道所需的步骤,我真的不需要知道填充 DataSet 的步骤。

How can I create a DataSet that is manually filled? ie. fill through the code or by user input. I want to know the required steps if I need to create a DataTable or a DataRow first, I really don't know the steps to fill the DataSet.

推荐答案

 DataSet ds = new DataSet();

 DataTable dt = new DataTable("MyTable");
 dt.Columns.Add(new DataColumn("id",typeof(int)));
 dt.Columns.Add(new DataColumn("name", typeof(string)));

 DataRow dr = dt.NewRow();
 dr["id"] = 123;
 dr["name"] = "John";
 dt.Rows.Add(dr);
 ds.Tables.Add(dt);

这篇关于向数据集添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆