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
619 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

792 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