Solved

BC30311: Value of type 'System.Data.DataView' cannot be converted to '1-dimensional array of System.Data.DataView'.

Posted on 2012-12-28
8
624 Views
Last Modified: 2012-12-28
I get the error "BC30311: Value of type 'System.Data.DataView' cannot be converted to '1-dimensional array of System.Data.DataView'." whith the below

 dvholidays = New DataView(dtholidays, "DATEPART(YEAR, Date) = " & e.Day.Date.Year & " AND " & "DATEPART(MONTH, Date) = " & e.Day.Date.Month, "", DataViewRowState.CurrentRows)


any idea why?
0
Comment
Question by:runnerjp2005
  • 4
  • 3
8 Comments
 

Author Comment

by:runnerjp2005
ID: 38726591
If it helps im looking to do a foreach loop where DATEPART(YEAR, Date) = " & e.Day.Date.Year & " AND " & "DATEPART(MONTH, Date) = " & e.Day.Date.Month,  in the datatable if there is an easyer why of doing this
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 38726659
the error lies in the way you declared dvholidays  variable.
it should be :
Dim dvholidays  as DataView
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38726661
if you declare the variable as array, you have to assign to a specific "slot" of the array:
dvholidays(1) = New DataView( ... )

or the like
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:runnerjp2005
ID: 38726677
i now get the following error :S The expression contains undefined function call DATEPART().
DATEPART(YEAR, Date) = " & e.Day.Date.Year & " AND " & "DATEPART(MONTH, Date) = " & e.Day.Date.Month,
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38726695
that's a new error ... should normally be a new question

anyhow, DATEPART is not a ADO function, so you cannot use it directly

you need to prepare the data in the underlying rowset in a way you can filter as needed.
either you have 2 fields containing only the year and month values; or you have the date field as string in format yyyymmdd etc ... and you can do >= '201101' and < '201201' if you want full year 2011 ...
0
 

Author Comment

by:runnerjp2005
ID: 38726705
what about between dates?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38726720
what I wrote above, you need to make the data in a way you can work correctly.
with dataviews, this can be tricky, as you don't have "all" the functions you may need to make it efficient.
note that usually, if the underlying sql can solve the filtering directly, especially if the filter would return only very few rows from a huge data set, you are better of querying with the filter direclty in the sql ...
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38726742
This question was asked (and probably answered) before I believe.

Execute a SQL to do the filtering from datasource (as probably already suggested).
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question