Home > Mobile >  How to display overall count of rows in a database in vb.net CHART Y AXIS
How to display overall count of rows in a database in vb.net CHART Y AXIS

Time:11-03

Edit i tried the RecCount from Hel o Ween's comment and it showed this exception RecCount

Heres my code, the x axis is working but the y axis show this error :Exception of Y axis

Im trying to make the x axis with all the same value in a specific column. And y axis as the overall counts of rows in a database

        Dim READER As OleDbDataReader
        Try

            Dim query As String
            query = "SELECT ID, purok  FROM Household"
            cmd = New OleDbCommand(query, con)
            READER = cmd.ExecuteReader
            Dim dT As New DataTable
            dT.Load(READER)


            Dim counter As String
            counter = dT.Rows.Count.ToString


            'Dim countrow = Convert.ToInt16(cmd.ExecuteScalar)
            'Label3.Text = countrow
            Chart1.Series("Purok").XValueMember = "Purok"
            Chart1.Series("Purok").YValueMembers = counter
            Chart1.DataSource = dT
            Chart1.DataBind()

            con.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

CodePudding user response:

Thanks to Hel O'Ween's comment and this thread: "You tried to execute a query that does not include the specified aggregate function" its fixed now. I just tweaked and added GROUP BY after the FROM statement.

Heres the result chart

Dim READER As OleDbDataReader
        Try

            Dim query As String
            query = "SELECT purok, COUNT(*) As RecCount FROM Household GROUP BY purok"
            cmd = New OleDbCommand(query, con)
            READER = cmd.ExecuteReader
            Dim dT As New DataTable
            dT.Load(READER)


          
            Chart1.Series("Purok").XValueMember = "purok"
            Chart1.Series("Purok").YValueMembers = "RecCount"
            Chart1.DataSource = dT
            Chart1.DataBind()

            con.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
  • Related