Solved

DataGrid/Data Display Question

Posted on 2004-10-26
238 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
Question by:NeoTek
    8 Comments
     
    LVL 25

    Expert Comment

    by:RonaldBiemans
    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
    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
    Give me a second, and i'll give you a possible solution
    0
     
    LVL 35

    Expert Comment

    by:YZlat
    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
    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:
    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
    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
    Sorry, forget my last comment. (WRONG ADJUSTMENT)
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

     Java Android Coding Bundle

    Whether you're an Apple user or Android addict, learning to code for the Android platform is an extremely valuable, in-demand skill. It all starts with Java, the language behind the apps and games that make Android the top platform it is today.

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    884 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now