简体   繁体   English

vb.net使用数组从数据表获取数据

[英]vb.net getting data from datatable using array

am making a chart, using highcharts, code behind is vb.net... 我正在制作图表,使用highcharts,后面的代码是vb.net ...

i have a datatable that is something like this: 我有一个像这样的数据表:

Date - speed - data
2011    10k     6
2011    18k     7
2012    20k     10
2012    10k      2
2013    14k      4
2013    20k      6

before when i wanted to get the datatble information for speed, i would use the following code: 在想获取速度的数据信息之前,我将使用以下代码:

 Dim a As DataSet = Cons
    Dim abc As DataTable
    abc = a.Tables(0)

 Dim array As New ArrayList

 For Each row In abc.Rows
        array.Add(row("Speed"))

    Next row

 Dim serializer As New JavaScriptSerializer()
  Dim arrayJson As String = serializer.Serialize(array)

so the code above will show me the data for speed. 因此上面的代码将向我显示速度数据。

however what if i want the data for 2011? 但是,如果我想要2011年的数据怎么办? or 2013. how would i get this, i have some code that has been done, but as i am using highchart i need to convert this in to array. 还是2013年。我该怎么做,我已经完成了一些代码,但是当我使用highchart时,我需要将其转换为数组。

how would i change this: 我将如何更改此:

For Each row In abc.Rows
        array.Add(row("Speed"))

    Next row

so that i can get the dates, any ideas anyone. 这样我就可以得到日期,任何想法。

ok, but what if the year is the same, but day is diffrent, 好的,但是如果年份相同但日子不同,该怎么办,

so 所以

01/10/2011 00:00:00
04/07/2011 00:00:00
21/11/2012 00:00:00
11/11/2013 00:00:00

so how do i call the date of 2011? 所以我怎么称呼2011年的日期?

Since 'abc' is a DataTable, you can use DataTable.Select method. 由于“ abc”是一个数据表,因此可以使用DataTable.Select方法。

For example to get the data for year 2011: 例如,获取2011年的数据:

For Each row In abc.Select("Date >= #1/1/2011# And Date <= #12/31/2011#")
  array.Add(row("Speed"))
Next row

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM