[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-04-22
3
Medium Priority
?
310 Views
Last Modified: 2012-05-06
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
Comment
Question by:JessyRobinson1234
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1500 total points
ID: 24213305
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
 
LVL 15

Expert Comment

by:NazoUK
ID: 24213591
You've put Chart.DataSource instead of Chart1.DataSource
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24213619
Good one Nazo. I missed that!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month18 days, 8 hours left to enroll

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question