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

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?
runnerjp2005Asked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
the error lies in the way you declared dvholidays  variable.
it should be :
Dim dvholidays  as DataView
0
 
runnerjp2005Author Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
runnerjp2005Author Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
runnerjp2005Author Commented:
what about between dates?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
CodeCruiserCommented:
This question was asked (and probably answered) before I believe.

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

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.