数据集和数据表 [英] Dataset and datatables

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

问题描述

大家好,

(我是C#的菜鸟)
从.xml文件读取
我需要从数据集中获取某些列到不同的表中.
将文件拆分为3个表.
任何想法都会有所帮助.

Hello all,

(I am a noob to c#)
reading from a .xml file
I need to get certain coloms from a data set into different tables.
splitting the file into 3 tables.
any ideas would help.

DataSet mydata = new DataSet("mydata");
mydata.ReadXml("C:\\Program Files (x86)\\MaxID\\MaxID Fastskan Driver\\Data\\FastSkanDriver.xml");
dataGridView1.DataSource = mydata.Tables[0];


说我有数据"ID号",名称",地址",电话号码"等.但只需要表1中的地址和电话号码以及表2中的名称和地址.


Say I have data "id number" "name" "address" "tel number" ect. but only want address and tel number in table 1 and name and address in table 2.

推荐答案

请尝试以下代码.
Try as below code.
DataSet mydata = new DataSet("mydata");
mydata.ReadXml("YourXmlFilePath");

DataTable firstDataTable = new DataTable();
DataTable secondDataTable = new DataTable();

if (mydata.Tables.Count > 0)
{
  firstDataTable = mydata.Tables[0].Copy();
  secondDataTable = mydata.Tables[0].Copy();

  //Remove columns from the first DataTable which you want to remove.
  firstDataTable.Columns.Remove("ColumnNameToRemove1");

  //Remove columns from the second DataTable which you want to remove.
  secondDataTable.Columns.Remove("ColumnNameToRemove2");
}


您可以手动"读取XML文件,并将每个项目转移到适当的数据集中,然后将其绑定到相关的数据网格.或者,您可以采用上面创建的数据集,然后将数据列中的数据手动复制到其他数据集中.无论哪种情况,都需要一些工作.
You could read the XML file ''manually'' and transfer each item into the appropriate dataset which you can then bind to the relevant datagrid. Alternatively you could take your dataset as created above and manually copy columns of data from that into other datasets. In either case it requires a bit of work.


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

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