Datagrid databinding with a SQL statement

Windsailor

Well-known member
Joined
Aug 2, 2006
Messages
45
Programming Experience
1-3
To set the stage, Tables are set up as such for this question:
-----------
Table: Answers
ID - Integer - Auto
Answer - Integer
QuestionID - Integer - FK from the QuizMaster table
StudentID - Integer - FK from the Students table

Table: QuizMaster

ID - Integer - Auto
Answer - Integer

Table: Students
ID - Integer - Auto
StudentName - Varchar(50)
----------

The SQL statement is:

VB.NET:
SELECT 
StudentName, 
TotalCorrect, 
TotalQuestions, 
CAST(([TotalCorrect])/([TotalQuestions])*100 as numeric(5,2)) AS PercentValue 

FROM ( 

SELECT Students.StudentName, 

CAST(COUNT(Students.StudentName) AS numeric(5, 2)) AS TotalCorrect, 

CAST((SELECT COUNT(QuizMaster.ID) FROM QuizMaster) AS numeric(5, 2)) AS TotalQuestions 

FROM (Answers 
     INNER JOIN Students 
ON Answers.StudentID = Students.ID) 
     INNER JOIN QuizMaster 
ON (Answers.Answer = QuizMaster.Answer) 
AND (Answers.QuestionID = QuizMaster.ID) 
GROUP BY Students.StudentName 
) t 

ORDER BY StudentName, PercentValue DESC

Which works great... returning the correct results.
But... I am having difficulty in binding a datagrid to show all of the results of the SQL statement... or you might say difficulty in creating a correct datasource for my datagrid.
I originally used an adapter that was (SELECT Answer FROM Answers) and then re-configured it with the above statement.
In the preview of the adapter I show the fields...
Answer, StudentName, TotalCorrect, TotalQuestions, PercentValue: with the correct values listed in them (The 'Answer' column being blank and the rest filled in).

But in the designer.vb portion of the dataset, only the 'Answer' column attributes are listed... and the rest of the custom columns do not exist.

Do I have to go in and manually create the attributes for those custom columns?

How else would I do this?
 
I think I made a mistake binding to an object or table when all I wanted was to process the query and return the results.
Maybe the question should have been how do I bind a datagrid to a custom query?

----

***Just a note***
It took me awhile to find this post and *where* someone put this.
I really don't think this is the appropriate forum since we are going to be talking about datasets, adapters etc. and really nothing about the datagrid functionality itself... this is about binding issues.
-Or-
Creating a correct binding source for the datagrid...................................
 
Last edited:
Back
Top