Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DataGrid/Data Display Question

Posted on 2004-10-26
8
Medium Priority
?
265 Views
Last Modified: 2010-04-23
Hi,

I have a form where users can go to fill out a survey.  There are 12 questions total.  I want to display this data somehow in the following format...

Total Submissions: 5

Date
                            Excellent   Good   Average   Fair   Poor |  Average
        Question 1          3            1          1          0        0          4.4
        Question 2          0            4          0          0        0          3.4
        Totals                3            5           1         0        1          4.0

Can I do this with a datagrid?  Currently in my database I have a list of submissions (Date, and Responses to Questions 1 - 12).  Would it be easier to sum the totals and get the averages in my database?  I am using SQL.  Or can I do this in my dataset?  Basically what is the easiest way to go about doing this.  Thanks.

Ryan
0
Comment
Question by:NeoTek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12410393
Hi NeoTek,

Yes, this is possible in a datagrid, (although it might be easier print the outcome in a textbox), just a question, what is in the
responses to questions 1-12, a number from 0 to 5 ?
0
 
LVL 1

Author Comment

by:NeoTek
ID: 12410421
Hi,

The responses to questions 1-12 are a number from 1-5.  How can I go about doing this?

NeoTek
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12410455
Give me a second, and i'll give you a possible solution
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:YZlat
ID: 12410513
Create a datatable, fill it from a database and then bind it to the datagrid or datalist

'Create the DataTable
 Dim dtTable As New DataTable()
dtTable.Columns.Add(New DataColumn(("question"), GetType(String)))
 dtTable.Columns.Add(New DataColumn(("excellent"), GetType(Integer)))
 dtTable.Columns.Add(New DataColumn(("good"), GetType(Integer)))
 dtTable.Columns.Add(New DataColumn(("average"), GetType(Integer)))
dtTable.Columns.Add(New DataColumn(("fair"), GetType(Integer)))
 dtTable.Columns.Add(New DataColumn(("poor"), GetType(Integer)))
dtTable.Columns.Add(New DataColumn(("totalavg"), GetType(Integer)))

''retrieve your data from the database with a datareader
Dim Reader as OleDbDataReader ''(or SQLDataReader)

.........................

While Reader.Read
      'Create Rows
         Dim dr As DataRow
         dr = dtTable.NewRow()
               
      dr("question")=Reader("question")
         dr("excellent") = Reader("excellent")
         dr("good") = Reader("good")
         dr("average") = Reader("average")
         dr("fair") = Reader("fair")
      dr("poor") = Reader("poor")
        dr("totalavg") = Reader("totalavg")
      
end while

'Now, create a DataView and order it by question number
Dim myDataView As DataView = dtTable.DefaultView
myDataView.Sort = "question"

'Now, bind the DataView to the DataGrid
DataGrid1.DataSource = myDataView

If you provide yourr db structure I can help you to fill out your datatable

       
0
 
LVL 1

Author Comment

by:NeoTek
ID: 12410689
My datatabes is called CSS_Input in a Database Intranet.  I put that into a dataset, DsCSS.  My fields are as follows...

ID - int
CurrentDate - datetime
R1 - int
R2 - int
R3 - int
R4 - int
R5 - int
R6 - int
R7 - int
R8 - int
R9 - int
R10 - int
R11 - int
R12 - int

That's all.  Thanks.

NeoTek
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 1000 total points
ID: 12410908
This seems to work,


Dim dt As New DataTable

    Private Sub Form17_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        OleDbDataAdapter1.Fill(dt)

        Dim dt2 As New DataTable
        dt2.Columns.Add("Question", GetType(System.String))
        dt2.Columns.Add("Excellent", GetType(System.Int32))
        dt2.Columns.Add("Good", GetType(System.Int32))
        dt2.Columns.Add("Average", GetType(System.Int32))
        dt2.Columns.Add("Fair", GetType(System.Int32))
        dt2.Columns.Add("Poor", GetType(System.Int32))
        dt2.Columns.Add("AVG", GetType(System.Single), "((Excellent*5) + (Good*4) + (Average*3) + (Fair*2) + (Poor*1))/(Excellent+Good+Average+Fair+Poor)")

        Dim dr As DataRow
        For x As Byte = 1 To 12
            dr = dt2.NewRow
            dr.Item(0) = "Question " & x
            dr.Item(1) = dt.Compute("count(R" & x & ")", "R" & x & "= 5")
            dr.Item(2) = dt.Compute("count(R" & x & ")", "R" & x & "= 4")
            dr.Item(3) = dt.Compute("count(R" & x & ")", "R" & x & "= 3")
            dr.Item(4) = dt.Compute("count(R" & x & ")", "R" & x & "= 2")
            dr.Item(5) = dt.Compute("count(R" & x & ")", "R" & x & "= 1")
            dt2.Rows.Add(dr)
        Next

        dr = dt2.NewRow
        dr.Item(0) = "Total"
        dr.Item(1) = dt2.Compute("sum(Excellent)", "")
        dr.Item(2) = dt2.Compute("sum(Good)", "")
        dr.Item(3) = dt2.Compute("sum(Average)", "")
        dr.Item(4) = dt2.Compute("sum(Fair)", "")
        dr.Item(5) = dt2.Compute("sum(Poor)", "")
        dt2.Rows.Add(dr)
        DataGrid1.DataSource = dt2
    End Sub
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12410981
A bit shorter ;-),

Private Sub Form17_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        OleDbDataAdapter1.Fill(dt)

        Dim dt2 As New DataTable
        dt2.Columns.Add("Question", GetType(System.String))
        dt2.Columns.Add("Excellent", GetType(System.Int32))
        dt2.Columns.Add("Good", GetType(System.Int32))
        dt2.Columns.Add("Average", GetType(System.Int32))
        dt2.Columns.Add("Fair", GetType(System.Int32))
        dt2.Columns.Add("Poor", GetType(System.Int32))
        dt2.Columns.Add("AVG", GetType(System.Single), "((Excellent*5) + (Good*4) + (Average*3) + (Fair*2) + (Poor*1))/(Excellent+Good+Average+Fair+Poor)")

        Dim dr As DataRow
        For x As Byte = 1 To 12
            dr = dt2.NewRow
            dr.Item(0) = "Question " & x
            For y As Byte = 1 To 5
                dr.Item(y) = dt.Compute("count(R" & x & ")", "R" & x & "= " & y)
            Next
            dt2.Rows.Add(dr)
        Next

        dr = dt2.NewRow
        dr.Item(0) = "Total"
        dr.Item(1) = dt2.Compute("sum(Excellent)", "")
        dr.Item(2) = dt2.Compute("sum(Good)", "")
        dr.Item(3) = dt2.Compute("sum(Average)", "")
        dr.Item(4) = dt2.Compute("sum(Fair)", "")
        dr.Item(5) = dt2.Compute("sum(Poor)", "")
        dt2.Rows.Add(dr)
        DataGrid1.DataSource = dt2
    End Sub

0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12410996
Sorry, forget my last comment. (WRONG ADJUSTMENT)
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

636 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