i have chart and i want fill it by searching between 2 dates ( my database is MS Access 2003 and i am using Vb.net Forms )

StackOverflow https://stackoverflow.com/questions/21075601

  •  27-09-2022
  •  | 
  •  

Question

i have chart and i want fill it by searching between 2 dates ( my database is MS Access 2003 and i am using Vb.net Forms ) the error in SQL statment and the image link down shows the error my code is

Try
        Dim MyStringDate1 As Date = CDate(DateTimePicker1.Value.Date)
        Dim MyStringDate2 As Date = CDate(DateTimePicker2.Value.Date)

        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source =" & Application.StartupPath & "\LIBRARY.mdb"
        con.Open()
        sql = "select CATEGORY , COUNT(CATEGORY)as CatStac from tblRentals where  dateIssued between   #" & MyStringDate1 & "# AND #" & MyStringDate2 & "#   from  tblRentals   GROUP BY CATEGORY"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "tblRentals")
        con.Close()
    Catch ex As Exception
        MsgBox(ex.Message)
        MsgBox(" SQL OR CONNECTION ERROR ")
    End Try

    Try
        Dim T As Title = Chart1.Titles.Add("CATEGORY STACS FOR LIBRARY")
        '~~> Formatting the Title
        With T
            .ForeColor = Color.Black            '~~> Changing the Fore Color of the Title 
            .BackColor = Color.Coral            '~~> Changing the Back Color of the Title 

            '~~> Setting Font, Font Size and Bold/Italicizing
            .Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold)
            .Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Underline)
            .BorderColor = Color.Black          '~~> Changing the Border Color of the Title 
            .BorderDashStyle = ChartDashStyle.DashDotDot '~~> Changing the Border Dash Style of the Title 
        End With
        Chart1.DataSource = ds.Tables("tblRentals")
        Dim Series1 As Series = Chart1.Series("Series1")
        Series1.Name = "CATEGORY STACS"
        Chart1.Series(Series1.Name).ChartType = SeriesChartType.Pie

        ' Chart1.Series(Series1.Name).LabelFormat = "0"
        Chart1.Series(Series1.Name).IsValueShownAsLabel = True
        Chart1.Series(Series1.Name).XValueMember = "CATEGORY"
        Chart1.Series(Series1.Name).YValueMembers = "CatStac"
        Dim LG As Legend = Chart1.Legends(0)
        '~~> Changing the Back Color of the Legend 
        LG.BackColor = Color.Wheat
        '~~> Changing the Fore Color of the Legend
        LG.ForeColor = Color.DarkSlateBlue
        '~~> Setting Font, Font Size and Bold
        LG.Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Bold)
        '~~> Assigning a title for the legend
        LG.Title = "Legend"
        Chart1.Size = New System.Drawing.Size(500, 500)
    Catch ex As Exception
        MsgBox(ex.Message)
        MsgBox("CHART ERROR ")
    End Try

http://s17.postimg.org/wqkde2fjj/image.png

Was it helpful?

Solution

try change the select like this :

sql = "select CATEGORY , COUNT(CATEGORY)as CatStac from tblRentals where  dateIssued  >  #" & MyStringDate1 & "# AND dateIssued  < #" & MyStringDate2 & "#   GROUP BY CATEGORY"

Add this to your code to bind your dataSet to chart :

'Set chart data source  
chart1.DataSource = ds  

'Set series members names for the X and Y values  
chart1.Series("Series 1").XValueMember = "col1"
chart1.Series("Series 1").YValueMembers = "col2"  

'Data bind to the selected data source  
chart1.DataBind()  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top