473,408 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Getting database fields (rows) to appear as columns in datagrid

I'm looking at a quick way to get results that are displayed as rows to
display as columns.

I have three tables:-
- The Questions for the survey
- The Results of the survey (Columns are listed as question numbers)
- The Survey Extra Results (As additional questions can be listed into
the Questions table, has 3 columns (a link/id to the survey id, a
link/id to the question id, and the answer the user gave).

I need to list the results of the survey and the extra results for the
survey on one row in a datagrid for each survey.

Any ideas?

Aug 6 '06 #1
1 1450
I currently have the following which basically makes a SQL query for
every single row required and makes a union, however this query can
easily get too complex and when 50+ surveys have been created, it will
start to lagg.

Dim j As Integer
dsSurveys = GetAllSurveys("Attendee")
For j = 0 To dsSurveys.Tables(0).Rows.Count - 1

SelectQuery = ""
dsQuestions = GetAllQuestionNumbers("Attendees")
If dsQuestions.Tables.Count <0 Then
If dsQuestions.Tables(0).Rows.Count <0 Then
Dim i As Integer
For i = 0 To
dsQuestions.Tables(0).Rows.Count - 1
If
GetColumns(dsQuestions.Tables(0).Rows(i).Item(0).T oString) <"" Then
SelectQuery +=
GetColumns(dsQuestions.Tables(0).Rows(i).Item(0).T oString) & " AS [" &
dsQuestions.Tables(0).Rows(i).Item(0).ToString & EndOfString(i,
CInt(dsQuestions.Tables(0).Rows.Count) - 1)
Else
SelectQuery += " (SELECT
SurveyExtra.SurveyExtra_Answer FROM SurveyExtra WHERE SurveyExtra_Guid
= '{" &
dsSurveys.Tables(0).Rows(j).Item("Survey_Additiona lQS").ToString & "}'
AND SurveyExtra_QuestionGuid = '{" &
dsQuestions.Tables(0).Rows(i).Item("Question_GuID" ).ToString & "}') AS
[" & dsQuestions.Tables(0).Rows(i).Item(0).ToString & "] "
If Not i =
(CInt(dsQuestions.Tables(0).Rows.Count) - 1) Then
SelectQuery += ", "
End If
End If
Next
End If
End If

Query += "SELECT Survey.Survey_Id AS [Survey_Id],
Survey.Survey_GuID AS [Survey_GuID], " & SelectQuery & " FROM Survey
WHERE Survey.Survey_Id = " & dsSurveys.Tables(0).Rows(j).Item(0) & "
AND Survey_Type = 'Attendee'"

If j = (dsSurveys.Tables(0).Rows.Count - 1) Then
Query += ";"
Else
Query += " UNION "
End If

Next

Aug 7 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added...
4
by: sivashankar | last post by:
hello experts.... -i'm having a datagrid with 10 columns and 4 rows and one submit button. -the fields are eno,ename,eid,and 4 check boxes -after entering values when i clik the submit button...
0
by: John Shum | last post by:
I prepare a UserControl that act as a lookup control, once the code is enter in the TextBox, the description will appear in another TextBox outside the UserControl of the same row in a DataGrid via...
3
by: | last post by:
I wrote a class in VB.NET to export the contents of a datagrid to Excel. It works perfectly on my machine, but it fails on my customers' PCs that have identical versions of Win XP (SP1) and Excel...
3
by: Frustrated Developer via DotNetMonster.com | last post by:
I have posted a couple times on here already and found the user community to be very helpful. I took on a project before I realized how difficult a time I'm having working with a database....
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
4
by: dallasfreeman | last post by:
I'm looking at a quick way to get results that are displayed as rows to display as columns. I have three tables:- - The Questions for the survey - The Results of the survey (Columns are listed...
3
by: =?Utf-8?B?SmliZXkgSmFjb2I=?= | last post by:
Hi: I have an interesting problem that I don't know how to solve. I need to display rows of one of these grid controls on two columns of the grid. So, row1 would appear on row1, column1, and...
1
by: tucson | last post by:
I have a gridview that has a blank row with 2 input fields: file to upload, and a description of the file. They click Add and a new row is added, Remove and the row is removed. The problem is:...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.