TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kasey
NA
1
14.3k
Saved Access2003 Query Works Fine in Access but not when Run in C#
Jan 22 2011 9:23 AM
Unfortunately I can't get to my code from home to write this post properly but here is the problem...
Background: I have an Access 2003 database (don't tell me to move to another database method, I can't, this is what I have to work with in the environment the client gave me). That database contains around 30,000 rows of data dealing with their vendor data such as total hours works, a score they've assigned to them, etc... I'm collecting data from this database to render a Vendor Summary report of sorts showing average hours, score, and other info grouped by the state and the vendor to produce 1 report per state/vendor group. Easy enough right?
I have a saved query in the database that collects all this data into one table for me. It is a large query, but not the largest I've ever made and certainly not the most complex. The query runs perfectly find within Access 2003 and shows me the proper totals and averages.
The Problem: I'm building a C# desktop application that will build the aforementioned summary data and will use that data to produce a specfically formated XML file to load into yet another application. I'm using OleDbCommand to run the stored query and then using OleDbDataAdapter to fill a DataTable. This works fine except some of the values from the query are showing up as a 0 rather than the number actually displayed in the query results in Access.
Here is a basic idea of how my query is written (just a small portion):
----------------
SELECT
[Vendor].[VendorID],
Count([Vendor].[WorkID]) as CountOfVendorWork,
[Vendor].[State],
Avg([Vendor].[CycleTime]) as AvgCycleTime,
(Select Count(Vendor1.[WorkID]) as CountOfClosed From [Vendor] as Vendor1 WHERE Vendor1.Status LIKE "Project:Closed:*" AND Vendor1.[State] = [Vendor].[State] AND Vendor1.[VendorID] = [Vendor].[VendorID]) as CountOfClosedProjects,
Sum([Payouts].TotalPaid) as SumTotalPaid
FROM
[Vendor]
LEFT JOIN [Payouts] ON [Payouts].[VendorID] = [Vendor].[VendorID]
GROUP BY [Vendor].[VendorID], [Vendor].[State]
---------------
This produces results such as:
VendorID CountOfVendorWork State AvgCycleTime CountOfClosedProjects SumTotalPaid
1 22 GA 30 8 100000
2 2 AZ 100 2 500000
But when I run the query using OleDB in C#, I get results such as:
VendorID CountOfVendorWork State AvgCycleTime CountOfClosedProjects SumTotalPaid
1 22 GA 30 0 0
2 2 AZ 100 0 500000
Why would the CountOfClosedProjects and SumTotalPaid be zero?? There are in the end about 30 columns all produced using the same methodology in the example. The main issues appear on the lines where I've used the LIKE statements. Is there a different way I have to code the LIKE statement for C# to recognize it? Note there are absolutely no errors being generated of any kind. The DataTable is filled but not with the expected values.
The SumTotalPaid only sometimes produces 0 instead of the proper value. I'm not sure why, but I'm less concerned about it at the moment. Any thoughts?
Reply
Answers (
0
)
How to bind three DataTables into one gridview, dynamically
How to create a MYSQL connection and display value in datagrid?