1

am making a chart, using highcharts, code behind is 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? 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.

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?

1 Answer 1

2

Since 'abc' is a DataTable, you can use DataTable.Select method.

For example to get the data for year 2011:

For Each row In abc.Select("Date >= #1/1/2011# And Date <= #12/31/2011#")
  array.Add(row("Speed"))
Next row
Sign up to request clarification or add additional context in comments.

6 Comments

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?
You should've mentioned that in your post. Please post correct date values. Also what DB you're using? SQL Server?
Assuming that it's a normal date field I've updated my answer.
So does the updated answer "Date >= #1/1/2011# And Date <= #12/31/2011#" work for u?
no, it wont because i have to many dates, i have some code that already defined this, e.g Dim Year1 As System.Data.EnumerableRowCollection(Of DataRow) year 1 shows the specific data, but i cant call it Dim a As DataSet = Year1 Year1 shows error
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.