如何从数据表中检索多行块? [英] How to retrieve multi-row blocks from a datatable?
问题描述
使用VB2005从
数据表中检索行块是否有简洁/有效的方法?
我有一个数据表(让's称之为AllData),以编程方式构建
,其中包含大量连续的科学数据,每行可能是每分钟的一行中的一个点。
数据可能延续数月。有一列
(Date_Time)设置为主键,其中包含每行的日期时间戳(作为
日期时间类型)。
我想做的是查询数据表中所有与
相关的行,比如说一天就像编码一样(我知道这不合法
VB):
Dim DailyData as datatable = AllData.Select(col(" Date_Time"))
datetime start-时间和日期时间<结束时间
我可以通过在AllData中的所有
行上''手动'迭代来做一些事情,但是我我希望找到一种更简单,也许更有价值的b $ b b方法。 AllData只是一个内存中的数据表,所以AIUI I
不能在数据表上使用标准的SQL查询,如果它是一个数据库的话。而且我坚持使用VB2005,所以我不相信我可以使用LINQ,这可能会让这很简单,例如VB2008。那么请问
其他选项吗?
Is there a concise/efficient way to retrieve blocks of rows from a
datatable with VB2005?
I''ve got a datatable (let''s call it AllData), constructed
programmatically, that contains a lot of sequential scientific data,
each row being a point in a time-course potentially every minute and
with data maybe extending over many months. There''s a column
(Date_Time) set as a primary key which contains a datetime stamp (as a
datetime type) for each row.
What I''d like to do is to query the datatable for all rows relating to
say a single day by coding something like (I know this isn''t legal
VB):
Dim DailyData as datatable = AllData.Select(col("Date_Time") where
datetime start-time AND datetime < end-time)
I could obviously do something by iterating ''manually'' over all the
rows in AllData, but I was hoping to find a simpler and maybe more
efficient approach. AllData is just an in-memory datatable so AIUI I
can''t use a standard SQL query on the datatable as I could if it were
a database. And I''m stuck with VB2005 so I don''t believe that I could
use LINQ, which might make this easy in eg VB2008. So are there any
other options please?
推荐答案
我假设AllData是一个System.Data.DataTable对象,如
所示,您的日常数据的示例行。您可以使用您列出的表达式等条件从表格中提取行块$
:
Dim Daily()as DataRow
Dim FilterString as String = String.Format(" datetime#{0}#AND datetime<
#{1}#",DateTime.Parse(开始时间),DateTime.Parse(结束时间))
每日= AllData.Select(FilterString)
" John Dann" < ne ** @ prodata.co.ukwrote in message
news:v1 ************************** ****** @ 4ax.com ...
I presume that AllData is a System.Data.DataTable object, as indicated in
your example line for the daily data.. You can extract a block of rows from
the table using criteria such as you have listed with an expression like:
Dim Daily() as DataRow
Dim FilterString as String = String.Format("datetime #{0}# AND datetime <
#{1}#", DateTime.Parse(start-time), DateTime.Parse(end-time))
Daily = AllData.Select(FilterString)
"John Dann" <ne**@prodata.co.ukwrote in message
news:v1********************************@4ax.com...
是否有一种简洁/有效的方法从
$ b $中检索行块b使用VB2005数据表?
我有一个数据表(让我们称之为AllData),以编程方式构造
,其中包含很多顺序科学数据,
每一行都是时间进程中的一个点,可能每分钟一次,而b / b $ b,数据可能延续数月。有一列
(Date_Time)设置为主键,其中包含每行的日期时间戳(作为
日期时间类型)。
我想做的是查询数据表中所有与
相关的行,比如说一天就像编码一样(我知道这不合法
VB):
Dim DailyData as datatable = AllData.Select(col(" Date_Time"))
datetime start-时间和日期时间<结束时间
我可以通过在AllData中的所有
行上''手动'迭代来做一些事情,但是我我希望找到一种更简单,也许更有价值的b $ b b方法。 AllData只是一个内存中的数据表,所以AIUI I
不能在数据表上使用标准的SQL查询,如果它是一个数据库的话。而且我坚持使用VB2005,所以我不相信我可以使用LINQ,这可能会让这很简单,例如VB2008。那么有什么
其他选择吗?
Is there a concise/efficient way to retrieve blocks of rows from a
datatable with VB2005?
I''ve got a datatable (let''s call it AllData), constructed
programmatically, that contains a lot of sequential scientific data,
each row being a point in a time-course potentially every minute and
with data maybe extending over many months. There''s a column
(Date_Time) set as a primary key which contains a datetime stamp (as a
datetime type) for each row.
What I''d like to do is to query the datatable for all rows relating to
say a single day by coding something like (I know this isn''t legal
VB):
Dim DailyData as datatable = AllData.Select(col("Date_Time") where
datetime start-time AND datetime < end-time)
I could obviously do something by iterating ''manually'' over all the
rows in AllData, but I was hoping to find a simpler and maybe more
efficient approach. AllData is just an in-memory datatable so AIUI I
can''t use a standard SQL query on the datatable as I could if it were
a database. And I''m stuck with VB2005 so I don''t believe that I could
use LINQ, which might make this easy in eg VB2008. So are there any
other options please?
On Mon,2008年11月10日11:53:00 +1100,James Hahn < jh *** @ yahoo.com>
写道:
On Mon, 10 Nov 2008 11:53:00 +1100, "James Hahn" <jh***@yahoo.com>
wrote:
>我认为AllData是System.Data.DataTable对象,如每日数据的示例行所示。您可以使用以下列表中的条件从表中提取行块:
Dim Daily()as DataRow
Dim FilterString as String = String.Format(" datetime#{0}#AND datetime<
#{1}#",DateTime.Parse(start -time),DateTime.Parse(end-time))
每日= AllData.Select(FilterString)
>I presume that AllData is a System.Data.DataTable object, as indicated in
your example line for the daily data.. You can extract a block of rows from
the table using criteria such as you have listed with an expression like:
Dim Daily() as DataRow
Dim FilterString as String = String.Format("datetime #{0}# AND datetime <
#{1}#", DateTime.Parse(start-time), DateTime.Parse(end-time))
Daily = AllData.Select(FilterString)
非常感谢。我可以在当天晚些时候详细了解一下
。是的,在我的例子中AllData确实是一个标准的
DataTable对象。
DataTable。是否有一个整洁的(我在想单行代码)的方式
将数组的数组(即Daily())重新组合成一个
DataTable?或者我是否需要以某种方式从原始的
数据表中克隆模式并实例化一个新的空数据表,然后通过Daily()中的所有行迭代
并添加每个转到新的
数据表?
Many thanks. I''ll be able to take a detailed look at this a little
later in the day. Yes in my example AllData was indeed a standard
DataTable object.
Ideally what I''d like to return is another - obviously smaller -
DataTable. Is there a neat (I''m thinking single line of code) way of
reassembling that array of datarows (ie Daily() ) back into a
DataTable? Or do I need to somehow clone the schema from the original
datatable and instantiate a new empty datatable and then iterate
through all the rows in Daily() and add each in turn to the new
datatable?
2008年11月10日星期一11:53:00 +1100,James Hahn < jh *** @ yahoo.com>
写道:
On Mon, 10 Nov 2008 11:53:00 +1100, "James Hahn" <jh***@yahoo.com>
wrote:
>我认为AllData是System.Data.DataTable对象,如每日数据的示例行所示。您可以使用以下列表中的条件从表中提取行块:
Dim Daily()as DataRow
Dim FilterString as String = String.Format(" datetime#{0}#AND datetime<
#{1}#",DateTime.Parse(start -time),DateTime.Parse(结束时间))
每日= AllData.Select(FilterString)
>I presume that AllData is a System.Data.DataTable object, as indicated in
your example line for the daily data.. You can extract a block of rows from
the table using criteria such as you have listed with an expression like:
Dim Daily() as DataRow
Dim FilterString as String = String.Format("datetime #{0}# AND datetime <
#{1}#", DateTime.Parse(start-time), DateTime.Parse(end-time))
Daily = AllData.Select(FilterString)
可悲的是我不能得到这个工作。在上面的FilterString定义中
如果我使用:
Dim FilterString as String = String.Format(" Date_Time#{0}#AND
DateTime,<#{1}#",DateTime.Parse(" 1/5/2008"),DateTime.Parse(
" 13/5/2008" ;))
(Date_Time是我的datetime列的列名,我正在工作
,包含2008年5月的一些数据)然后我得到:
FilterString =" Date_Time>#1/5/2008 00:00:00#AND Date_Time
<#13/5/2008 00 :00:00#"
看起来像预期的那样。但是在线上
每日= AllData.Select(FilterString)
a''FormatException not handling''error''字符串未被识别作为一个
有效的DateTime''被抛出。
看起来这个建议试图从日期时间类型中选择
列搜索一个字符串类型,可能(?)不能工作?
我的代码片段中是否有错误我没有发现?或者是
还有其他一些格式化过滤字符串的方法,它会在日期时间类型上过滤
吗?
Sadly I can''t get this to work. In the above FilterString definition
if I use:
Dim FilterString as String = String.Format("Date_Time #{0}# AND
DateTime ,<#{1}#", DateTime.Parse("1/5/2008"), DateTime.Parse(
"13/5/2008"))
(Date_Time is the column name for my datetime column and I''m working
with some data from May 2008) then I get:
FilterString = "Date_Time >#1/5/2008 00:00:00# AND Date_Time
<#13/5/2008 00:00:00#"
which seems as expected. But at the line
Daily = AllData.Select(FilterString)
a ''FormatException not handled'' error ''String was not recognised as a
valid DateTime'' is thrown.
It seems like this suggestion is trying to select from a datetime type
column by searching on a string type, which maybe (?) can''t work?
Is there an error in my code snippett that I haven''t spotted? Or is
there some other way of formatting the filter string that will filter
on datetime types?
这篇关于如何从数据表中检索多行块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!