Follow us on twitter

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.


  1.  
    Hello, I am having a hard time trying to create charts in vb using data from a access database. this is what i have so far and it does not produce a chart. I was wondering if someone could tell me what i am doing wrong and point me in the right direction.

    Code:
    Imports System.Data
    Imports System.Data.OleDb
    Imports System.Windows.Forms.DataVisualization.Charting


    Public Class Attendence_By_Hall

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            LoadChart()
        End Sub

        Sub LoadChart()
            Dim dt As New DataTable
            Dim dv As New DataView
            dt = GetData("7")

            dv = New DataView(dt)
            Chart1.ChartAreas("ChartArea1").Area3DStyle.Enable3D = True

            Chart1.Series.Clear()

            Chart1.Palette = ChartColorPalette.Pastel

            Chart1.DataBindTable(dv, "NUM_ATTEND")

            Chart1.Series(0).Name = "Hall1"
            Chart1.Series(0).ChartType = SeriesChartType.Line

        End Sub
        Function GetData(ByVal Name As String) As DataTable
            Dim fileNameString As String
            Dim dt As New DataTable

            fileNameString = "c\Temp\test.mdb"

            Dim ConnnectionString As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString

            Dim SQL As String = "SELECT RL_Events.NUM_ATTEND FROM RL_Events INNER JOIN RA_NAME ON RL_Events.SPONSOR_ID=HALL.ID where Hall.Hall_Name= '" & Name & "'"

            Dim conn As New OleDbConnection(ConnnectionString)

            Dim Command As New OleDbCommand(SQL, conn)

            conn.Open()

            Dim da As New OleDbDataAdapter(Command)
            da.Fill(dt)

            conn.Close()


            Return dt

        End Function
    End Class

  2.  
    why are you clearing the chart in load chart function?

  3.  
    I am clearing it because that is how it is in the example I saw.

    • CommentAuthorihmed2
    • CommentTimeNov 10th 2009
     
    Oh. Did you copy all of the above code? Make sure that there actually is a "chart1" object on the form. It looks like something you drag from the toolbox onto the form in design mode, then refer to in the code. Are there any error messages when you debug or build the project?

    • CommentAuthorA1sporty15
    • CommentTimeNov 10th 2009
     
    Yeah, it is something you can just drag on. My problem now is a syntax error with the inner join in my SQL string
    Code:

    Dim SQL As String = "SELECT RL_Events.NUM_ATTEND FROM RL_Events INNER JOIN RA_NAME ON RL_Events.SPONSOR_ID=HALL.ID where HALL.HALL_NAME= '" & Name & "'"


    Ive never used select or join statements before, so my next step is to learn that.

    • CommentAuthorihmed2
    • CommentTimeNov 10th 2009
     
    WTF is "System.Windows.Forms.DataVisualization.Charting"? Are you using an add-on or VS 2010? Because my VS 2008 doesn't know what that class is.

    • CommentAuthorA1sporty15
    • CommentTimeNov 10th 2009
     
    Its Microsoft chart controls add-on for visual studio 2008

    • CommentAuthorlimpeh
    • CommentTimeNov 11th 2009
     
    What are the names of the tables you are trying to join, and what columns in each table? WHat info are you trying to retrieve>?

    • CommentAuthorlimpeh
    • CommentTimeNov 11th 2009
     
    Here's a little trick I learned when using Access databases.. You can get access to write the SQL statement for you.

    In Access create a Query that join the information you want to pull out, After testing the query to make sure it is correct With the query open, click View>SQL view and it will give you the SQL code you need.

    If you try to view the query in access and you get an error then you know the problem is with one of the tables like a mismatch (you can join numbers and text etc)

    • CommentAuthorA1sporty15
    • CommentTimeMar 30th 2010
     
    Thanks for the tip Quxote. Sorry for not responding quicker, it was kind of a hectic week last week.