• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

How to data bind Chart with SQL server's stored procedure: reference to a non-shared member requires an object reference

I am trying to build a chart based on conditional queries and I ma very new to this. I am getting the error on the following line:

Chart.DataSource = source
--> reference to a non-shared member requires an object reference

Can someone guide me through this?
Imports ClassLibrary
Imports Dundas.Charting.WebControl
Imports System.Data.SqlClient
Imports System.IO
Imports System.Drawing
 
 Dim strShift As String
        Dim sqlStr As String
        Dim sConn As String = ConfigurationManager.ConnectionStrings("EGLYMSConnectionString").ToString
        Dim myConnection As SqlConnection = New SqlConnection(sConn)
        Dim myCommand As SqlDataAdapter = New SqlDataAdapter
        myCommand = New SqlDataAdapter(sqlStr, myConnection)
 
 
        myConnection.Open()
 
 
        If DatePart(DateInterval.Hour, Now()) >= 4 And DatePart(DateInterval.Hour, Now()) <= 15 Then
            strShift = "1st Shift"
        Else
            strShift = "2nd Shift"
        End If
        '    Determine Number of Trucks
        If strShift = "1st Shift" Then
            sqlStr = "SELECT V.CVEHICLENUMBER AS [VEHICLE_NUMBER], COUNT(YMH.IYARDMOVEHISTORYID) AS [COUNT], Cast(Avg((Datediff(s, dAdded, dArchived) / 60.0)) AS Decimal(4,2)) AS [Cycle_Time] FROM YARDMOVEHISTORY AS YMH WITH(NOLOCK) JOIN VEHICLES AS V WITH(NOLOCK) ON V.IVEHICLEID = YMH.IVEHICLEID WHERE (DATEPART(HH,YMH.DADDED) BETWEEN 4 AND 15) AND DATEDIFF(D,DADDED,GETDATE()) = 0 AND YMH.CSTATUS = 'COMPLETE' AND YMH.ISITEID = '3' AND V.LACTIVE = '1' GROUP BY V.CVEHICLENUMBER ORDER BY V.CVEHICLENUMBER;", myConnection)
        ElseIf strShift = "2nd Shift" And DatePart(DateInterval.Hour, Now()) >= 16 And DatePart(DateInterval.Hour, Now()) <= 23 Then
            sqlStr = "SELECT V.CVEHICLENUMBER AS [VEHICLE_NUMBER], COUNT(YMH.IYARDMOVEHISTORYID) AS [COUNT], Cast(Avg((Datediff(s, dAdded, dArchived) / 60.0)) AS Decimal(4,2)) AS [Cycle_Time] FROM YARDMOVEHISTORY AS YMH WITH(NOLOCK) JOIN VEHICLES AS V WITH(NOLOCK) ON V.IVEHICLEID = YMH.IVEHICLEID WHERE (DATEPART(HH,YMH.DADDED) BETWEEN 16 AND 23) AND DATEDIFF(D,DADDED,GETDATE()) = 0 AND YMH.CSTATUS = 'COMPLETE' AND YMH.ISITEID = '3' AND V.LACTIVE = '1' GROUP BY V.CVEHICLENUMBER ORDER BY V.CVEHICLENUMBER;", myConnection)
        ElseIf strShift = "2nd Shift" And DatePart(DateInterval.Hour, Now()) >= 0 And DatePart(DateInterval.Hour, Now()) <= 3 Then
            sqlStr = "SELECT V.CVEHICLENUMBER AS [VEHICLE_NUMBER], COUNT(YMH.IYARDMOVEHISTORYID) AS [COUNT], CAST(AVG((DATEDIFF(S, DADDED, DARCHIVED) / 60.0)) AS DECIMAL(4,2)) AS [CYCLE_TIME] FROM YARDMOVEHISTORY AS YMH WITH(NOLOCK) JOIN VEHICLES AS V WITH(NOLOCK) ON V.IVEHICLEID = YMH.IVEHICLEID WHERE ((DATEPART(HH,YMH.DADDED) BETWEEN 16 AND 23) AND DATEDIFF(D,DADDED,GETDATE()) = 1 AND YMH.CSTATUS = 'COMPLETE' AND YMH.ISITEID = '3' AND V.LACTIVE = '1') OR ((DATEPART(HH,YMH.DADDED) BETWEEN 0 AND 3) AND DATEDIFF(D,DADDED,GETDATE()) = 0 AND YMH.CSTATUS = 'COMPLETE' AND YMH.ISITEID = '3'  AND V.LACTIVE = '1') GROUP BY V.CVEHICLENUMBER ORDER BY V.CVEHICLENUMBER;", myConnection)
        End If
        ' create a database reader    
 
        Dim ds As New DataSet
        myCommand.Fill(ds)
 
        dim SqlDataAdapter as myCommand = new SqlDataAdapter(sqlStr, myConnection);
        ' Create and fill a DataSet.
        Dim DataSet As ds = New DataSet()
        myCommand.Fill(ds)
 
        Dim source As DataView
        source = New DataView(ds.Tables(0))
        Chart.DataSource = source
        Chart1.Series(0).ValueMemberX = "salesid"
        Chart1.Series(0).ValueMembersY = "Sales"
 
        ' Populate the chart with data from the data source
        Chart1.DataBind()

Open in new window

0
JessyRobinson1234
Asked:
JessyRobinson1234
  • 2
1 Solution
 
CodeCruiserCommented:
Where is the Chart declared? You can change the code from this

        Dim source As DataView
        source = New DataView(ds.Tables(0))
        Chart.DataSource = source
        Chart1.Series(0).ValueMemberX = "salesid"
        Chart1.Series(0).ValueMembersY = "Sales"

to this

        Chart.DataSource = ds.tables(0).DefaultView
        Chart1.Series(0).ValueMemberX = "salesid"
        Chart1.Series(0).ValueMembersY = "Sales"
0
 
NazoUKCommented:
You've put Chart.DataSource instead of Chart1.DataSource
0
 
CodeCruiserCommented:
Good one Nazo. I missed that!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now