Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a SQL query used to page through a database but throws this message once the OleDbDataAdapter executes it's fill command. The exact error message:

"IErrorInfo.GetDescription failed with E_FAIL(0x80004005)."

I have tested my SQL query in Access with success, seeing as Access can handle this query I'm completely stumped as to what is the problem. My working, yet not as elegant as I may want, SQL query where PageSize and intSkip are integers indicating the number of records on a page as well as the sum total of records on previous pages respectably:

SQL
SELECT TOP " + this.PageSize + " * FROM(SELECT SiteName, DateTimeMeas FROM (SELECT TOP " + this.PageSize + " * FROM (SELECT TOP " + intSkip + " * FROM ( SELECT DISTINCT SiteName, DateTimeMeas FROM TimeDep )) AS internal ORDER BY SiteName DESC) AS external ORDER BY SiteName ASC)


Any help will be appreciated.
Posted
Updated 2-Jul-12 2:21am
v3
Comments
bhagirathimfs 2-Jul-12 7:47am    
What is pageSize here?
Midichlorianite 2-Jul-12 7:58am    
The number of records that fit on one page. Sorry for not clarifying. intSkip is the amount of records it can skip due to having been on previous pages.
bhagirathimfs 2-Jul-12 8:06am    
that is an integer??
Midichlorianite 2-Jul-12 8:07am    
Indeed. I should have added "int" to the name now that I look at it.

1 solution

There are several problems.

1. You need to alias your innermost derived table.
2. external is a reserved word in SQL so put [] around it.
3. You need a TOP in your 2nd SELECT before SiteName, DateTimeMeas
4. You need to alias the outermost table.

Try this

SQL
SELECT TOP 10 * 
FROM(
	SELECT TOP 10 SiteName, DateTimeMeas 
	FROM (
		SELECT TOP 10 * 
		FROM (
			SELECT TOP 10 * 
			FROM ( 
				SELECT DISTINCT SiteName, DateTimeMeas 
				FROM TimeDep 
			) y
		) AS internal 
		ORDER BY SiteName DESC
	) AS [external]
ORDER BY SiteName ASC) x 
 
Share this answer
 
Comments
Midichlorianite 2-Jul-12 8:26am    
Thank you very much. This solved all my problems.
ZurdoDev 2-Jul-12 8:30am    
Good to hear.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900