Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 )
you can see the error in SQL statment see the link
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[^]
Posted
Updated 12-Jan-14 3:53am
v5

1 solution

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

You have already mentioned the FROM clause, no need to mention again before GROUP BY Clause.
 
Share this answer
 
Comments
MAlik Al-Hajaj 12-Jan-14 10:15am    
I DELETE ( from tblRentals ) BUT STILL RETURN ALL COLUMNS NOT COLUMNS BETWEEN 2 DATES

IT SHOULD RETURN 10 VALUES BUT NOW RETURN ALL VALUES
While debugging check what is the query it makes while running the code. Make sure that it is correct.
However, your exception is solved, so you can accept this answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900