By using Dev express chart control am populating some of charts which are based on today,yesterday,week ,months and year based query.But the Problem is that am getting this error .
The datasource doesn't contain a datamember with the "duration" name.
where getDataset is global function which am using from last 6 months which is perfectly alright.plz help. help is appreciated
Here is my complete method
Protected Sub populateLoginHistoryChart(ByVal ddlSelectedValue As String)
Dim sqlQuery As String = Nothing
sqlQuery = "SELECT LT.LogOnTime AS duration , COUNT(*) AS posts "
sqlQuery += " FROM ( "
sqlQuery += "SELECT CASE"
sqlQuery += " When DATEPART(hh,[LogOnTime]) >= 0 AND DATEPART(hh,[LogOnTime]) <= 4 AND DATEPART(mm,[LogOnTime]) <= 59 then '00:00-04:00'"
sqlQuery += " When DATEPART(hh,[LogOnTime]) >= 4 AND DATEPART(hh,[LogOnTime]) <= 8 AND DATEPART(mm,[LogOnTime]) <= 59 then '04:00-08:00' "
sqlQuery += " When DATEPART(hh,[LogOnTime]) >= 8 AND DATEPART(hh,[LogOnTime]) <= 12 AND DATEPART(mm,[LogOnTime]) <= 59 then '08:00-12:00' "
sqlQuery += " When DATEPART(hh,[LogOnTime]) >= 12 AND DATEPART(hh,[LogOnTime]) <= 16 AND DATEPART(mm,[LogOnTime]) <= 59 then '12:00-16:00' "
sqlQuery += " When DATEPART(hh,[LogOnTime]) >= 16 AND DATEPART(hh,[LogOnTime]) <= 20 AND DATEPART(mm,[LogOnTime]) <= 59 then '16:00-20:00' "
sqlQuery += " When DATEPART(hh,[LogOnTime]) >= 20 AND DATEPART(hh,[LogOnTime]) <= 23 AND DATEPART(mm,[LogOnTime]) <= 59 then '20:00-23:00' "
sqlQuery += " End as LogOnTime "
sqlQuery += " FROM StudentLoginHistory"
If ddlSelectedValue = "Today" Then
sqlQuery += " WHERE DATEADD(dd, 0, DATEDIFF(dd, 0, LogOnTime)) = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))"
sqlQuery += " )LT "
ElseIf ddlSelectedValue = "Yesterday" Then
sqlQuery += " WHERE DATEADD(dd, 0, DATEDIFF(dd, 0, LogOnTime)) = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))-1 "
sqlQuery += " )LT "
End If
sqlQuery += " GROUP BY LT.LogOnTime"
sqlQuery += " ORDER BY duration"
If ddlSelectedValue = "Week" Then
sqlQuery = "SELECT CONVERT(varchar(25),LogOnTime,107) AS duration, count(*) AS posts"
sqlQuery += " FROM StudentLoginHistory WHERE "
sqlQuery += " DateDiff(Week,LogOnTime,GetDate())=1"
sqlQuery += " GROUP BY CONVERT(varchar(25),LogOnTime,107)"
sqlQuery += " ORDER BY duration"
ElseIf ddlSelectedValue = "Month" Then
sqlQuery = "SELECT LT.LogOnTime AS duration, COUNT(*) AS posts"
sqlQuery += " FROM (SELECT CASE "
sqlQuery += " When DATEPART(dd,[LogOnTime]) >= 1 AND DATEPART(dd,[LogOnTime]) <= 7 then '2013-05-01 to 2013-05-07'"
sqlQuery += " When DATEPART(dd,[LogOnTime]) >= 8 AND DATEPART(dd,[LogOnTime]) <= 14 then '2013-05-08 to 2013-05-14'"
sqlQuery += " When DATEPART(dd,[LogOnTime]) >= 15 AND DATEPART(dd,[LogOnTime]) <= 21 then '2013-05-15 to 2013-05-21' "
sqlQuery += " When DATEPART(dd,[LogOnTime]) >= 22 AND DATEPART(dd,[LogOnTime]) <= 28 then '2013-05-22 to 2013-05-28'"
sqlQuery += " End as LogOnTime "
sqlQuery += " FROM StudentLoginHistory"
sqlQuery += " WHERE(DatePart(mm, LogOnTime) = DatePart(mm, DateAdd(mm, -1, getdate())) AND DatePart(yyyy, LogOnTime) = DatePart(yyyy, DateAdd(mm, -1, getdate())))"
sqlQuery += " )LT "
sqlQuery += " GROUP BY LT.LogOnTime"
ElseIf ddlSelectedValue = "Year" Then
sqlQuery = "SELECT CONVERT(varchar(4),LogOnTime , 100) + CONVERT(varchar(4), LogOnTime, 120) AS duration,COUNT(*) AS posts"
sqlQuery += " FROM StudentLoginHistory WHERE "
sqlQuery += " year(LogOnTime) = year(DATEADD(year,-1,getdate())) "
sqlQuery += "GROUP BY CONVERT(varchar(4),LogOnTime , 100) + CONVERT(varchar(4), LogOnTime, 120) "
sqlQuery += "ORDER BY month(CONVERT(varchar(4),LogOnTime , 100) + CONVERT(varchar(4), LogOnTime, 120))"
End If
Dim ds As DataSet = objglb.getDataset(sqlQuery, "tbl")
Dim Title As New DevExpress.XtraCharts.ChartTitle()
Dim Diagram As XYDiagram = CType(LoginHistoryChart.Diagram, XYDiagram)
LoginHistoryChart.Titles.Clear()
Dim Series As New Series("Series", ViewType.Bar)
LoginHistoryChart.Series.Add(Series)
Series.DataSource = ds
Series.ArgumentDataMember = "duration"
Series.ValueScaleType = ScaleType.Numerical
Series.ValueDataMembers.AddRange(New String() {"posts"})
If ddlSelectedValue = "Today" Then
Title.Text = "Login History By Today"
ElseIf ddlSelectedValue = "Yesterday" Then
Title.Text = "Login History By Yesterday"
ElseIf ddlSelectedValue = "Week" Then
Title.Text = "Login History By Last Week"
ElseIf ddlSelectedValue = "Month" Then
Title.Text = "Login History By Last Month"
ElseIf ddlSelectedValue = "Year" Then
Title.Text = "Login History By Last Year"
End If
'the appearance of the X-axis title.
Diagram.AxisX.Title.Visible = True
Diagram.AxisX.Title.Alignment = StringAlignment.Center
If ddlSelectedValue = "Today" OrElse ddlSelectedValue = "Yesterday" Then
Diagram.AxisX.Title.Text = "Hours"
ElseIf ddlSelectedValue = "Week" Then
Diagram.AxisX.Title.Text = "Days"
ElseIf ddlSelectedValue = "Month" Then
Diagram.AxisX.Title.Text = "Weeks"
ElseIf ddlSelectedValue = "Year" Then
Diagram.AxisX.Title.Text = "Months"
End If
Diagram.AxisX.Title.TextColor = Color.Black
Diagram.AxisX.Title.Font = New Font("georgia", 12, FontStyle.Regular)
Diagram.AxisX.Range.Auto = False
'the appearance of the Y-axis title.
Diagram.AxisY.Title.Visible = True
Diagram.AxisY.Title.Alignment = StringAlignment.Center
Diagram.AxisY.Title.Text = "Logins Counts"
Diagram.AxisY.Title.TextColor = Color.Black
Diagram.AxisY.Title.Antialiasing = True
Diagram.AxisY.Title.Font = New Font("georgia", 10)
CType(Series.View, SideBySideBarSeriesView).ColorEach = True
LoginHistoryChart.Width = 900
LoginHistoryChart.Legend.Visible = False
LoginHistoryChart.Titles.Add(Title)
Title.Font = New Font("georgia ", 14)
End Sub