数据表/集合中的数据操作(C#) [英] Datamanipulation in Datatables/sets (C#)

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

问题描述

Hello社区。



我在DataTabel / Set中遇到Datamanipulation的特定问题。

首先我从框架开始。



数据来源:一个大的MS EXCEL(2003)工作表。 (称之为Source.xls)

我的程序,应该如何操作和分析一些数据。

输出应该是另一个Excel ...



问题:

将所有数据从Source.xls读入我的DataTabel(称为myTestTable)。我想用SQL或其他东西过滤它。



输入:

Hello Community.

I have a specific Problem with Datamanipulation in DataTabel/Set.
First I start with the framework.

Data Sources: A Big MS EXCEL (2003) worksheet with. (Call it Source.xls)
My Program, how should manipulate and analyses some Data.
Output should be another Excel ...

The Problem:
After reading in all the Data from the Source.xls into my DataTabel (called myTestTable). I would like to filter it with SQL or something.

Input:

myExcelConnecter_YieldetValue = new MyExcelConnector();
DataTable myTestTable = new DataTable();
myTestTable = (myExcelConnecter_YieldetValue.getExcelData("PathToSource.xls", "SELECT * FROM [ABC$A2:FL3000]''"));



into myTestTable



我想过滤一些列,然后查询一些单元格(使用SQL)。



1)所以首先我尝试更改导入SQL


into myTestTable

I would like to filter some Columns and then query some Cells (with SQL).

1)So first i tryed change the Import SQL

"SELECT * FROM [ABC$A2:FL3000]'"

"SELECT * FROM [ABC$A2:FL3000] WHERE A$ ='name'"





但语法没有'工作(以及使用SQL / ADB / OleDB / ...从Excel中获取数据的googeling对我没有帮助。



2)查询DataTable:

相同的这里我只能使用.Select过滤行,但我需要过滤列,然后搜索(使用SQL)获取特定单元格中的值。

SQL看起来像这样。



But the Syntax didn''t work (and googeling for "Get Data from Excel with SQL/ADB/OleDB/..." did not help me.

2) Query the DataTable:
The Same Here I only can filter for Rows with .Select but i need to filter the Columns and then search (with SQL) for an Value in a specific Cell.
The SQL would look like this.

Select name, staat, city from myTestTable where name Like 'Testera'; 



但我不知道如何在DataTable对象中执行此操作。



3)我试过在foreach循环中更改DataTable。

但是当他处于循环中时你不能改变表。

首先我想只复制我需要的表格到单独的DataTable。


But i have no idea how to do this in a DataTable Object.

3)The i Tried to change the DataTable in an foreach-loop.
But you can''t change the Table while he is in the loop.
First i Want to copy only the tables i need to a seperate DataTable.

foreach (DataColumn myCol in myTestTable.Columns) 
{
   if (myCol.ColumnName.ToString() == "name")
   {
      myCOpy.Columns.Add(myCol);
   }
}



但我收到错误(列''名称''已经属于另一个DataTable)



然后我想删除我不使用的所有列(我不想拥有)


But i get the Error (Column ''name'' already belongs to another DataTable)

Then i want to delete all columns i don''t use (i won''t want to have)

myExcelConnecter_YieldetValue = new MyExcelConnector();
DataTable myTestTable = new DataTable();
myTestTable = (myExcelConnecter_YieldetValue.getExcelData("PathToSource.xls", "SELECT * FROM [ABC$A2:FL3000]'"));
List<String> myKillerCol = new List<string>();
foreach (DataColumn myCol in myTestTable.Columns) 
{
   if (myCol.ColumnName.ToString() != "name")
   {
      myKillerCol.Add(myCol.ColumnName.ToString());
   }
}
foreach (String myStringrunner in myKillerCol) 
{
   myTestTable.Columns.Remove(myStringrunner);
}





这有用但但表现是邪恶的。我必须这样做200次,一次需要30-40秒。



4)我将所有数据写入数据库,我知道如何选择操作一些东西。但如果你不能帮助我,这只是一个选择。

或者如果你说选项4的表现是最好的。



Thx阅读所有这些,我愿意接受任何帮助/提示/建议/ ...

问候

Ben



That worked BUT the performance was evil. I have to do this like 200 times and one time takes 30-40sec.

4) I write all the Data to a Database where i know how to select an manipulate some Stuff. But this is only an Option if you can''t help me.
Or if you say the performance of Option 4) is the Best.

Thx for reading all this and i am open for any help/tips/advise/...
Greetings
Ben

推荐答案

A2:FL3000]''));
A2:FL3000]''"));



进入myTestTable



我想过滤一些列,然后查询一些单元格(使用SQL)。



1)所以首先我尝试更改导入SQL


into myTestTable

I would like to filter some Columns and then query some Cells (with SQL).

1)So first i tryed change the Import SQL

"SELECT * FROM [ABC


A2:FL3000]'
A2:FL3000]'"

"SELECT * FROM [ABC


A2:FL3000]在哪里
A2:FL3000] WHERE A


这篇关于数据表/集合中的数据操作(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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