Solved

Pass Parameter to Stored Procedure

Posted on 2013-06-10
29
533 Views
Last Modified: 2013-06-12
I need to pass a parameter to a stored procedure from code.

I asked this question and applied the answer before testing.
The answer suggested modifying the Stored Procedure and introduced an error.
I changed the stored procedure back to the original, which fixed the error but still did not
pass the parameter.

Please help.

Thanks

This is the stored procedure:

ALTER PROCEDURE [dbo].[usp_getPriceChart]
      -- Add the parameters for the stored procedure here
AS
DECLARE      @SymbolID AS integer

BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

SELECT QuoteDate, ClosePrice
      FROM StockHist
    WHERE SymbolID=@SymbolID AND QuoteDate <= GETDATE()
      AND QuoteDate >= DATEADD(day,-65,GETDATE())
    ORDER BY QuoteDate

     
      END

Here is the c# code:

Int16 intSymbolID = 6939;

 SqlCommand cmdGetChartData = new SqlCommand();
            cmdGetChartData.CommandType = CommandType.StoredProcedure;
            cmdGetChartData.CommandText = "usp_getPriceChart";

            // Add the input parameter and set its properties.
            SqlParameter parameter = new SqlParameter();
            parameter.ParameterName = "@SymbolID";
            parameter.SqlDbType = SqlDbType.Int;
            parameter.Direction = ParameterDirection.Input;
            parameter.Value = intSymbolID;
            cmdGetChartData.Parameters.Add(parameter);

            dscWatchListChart.SelectCommand = cmdGetChartData.CommandText;  

dscWatchListChart.DataBind();  // Data is not displayed.

Works when the stored procedure is hard coded.
SET @SymbolID = 6939

What should I change?

Thanks
0
Comment
Question by:Dovberman
  • 13
  • 10
  • 5
  • +1
29 Comments
 

Author Comment

by:Dovberman
ID: 39234409
The previously suggested change was applied.

Change from
ALTER PROCEDURE [dbo].[usp_getPriceChart]
      -- Add the parameters for the stored procedure here
AS
DECLARE      @SymbolID AS integer

BEGIN

To:

ALTER PROCEDURE [dbo].[usp_getPriceChart]
   @SymbolID AS integer
      -- Add the parameters for the stored procedure here
AS
BEGIN

This caused an error. I changed it back to :

ALTER PROCEDURE [dbo].[usp_getPriceChart]
      -- Add the parameters for the stored procedure here
AS
DECLARE      @SymbolID AS integer

BEGIN

Now there is no error, but the parameter is not passed.
0
 
LVL 4

Accepted Solution

by:
BAKADY earned 290 total points
ID: 39234423
it is a long time since i worked with .Net and SQL, but i use to do this a little bit unusual...
do not use CommandType = StoredProcedure, just as a SQL Statement,...
then pass it a SQL-string like this (no select) :

CALL  usp_getPriceChart(1, 2, 3)  <<< 1, 2, 3 are your parameters, or
CALL  usp_getPriceChart('somestring')

regards
0
 
LVL 44

Assisted Solution

by:Rainer Jeschor
Rainer Jeschor earned 20 total points
ID: 39234485
Hi,
sorry, but what is the error you get?
I have hundreds of stored procedures being called by ASP.NET and the parameter has to be BEFORE the BEGIN and after the ALTER/CREATE PROCEDURE and does not need to have a DECLARE - as you can also see with the comment generated by SQL Server when you create a blank SPROC.
0
 
LVL 4

Assisted Solution

by:BAKADY
BAKADY earned 290 total points
ID: 39234505
i think i have misunderstood something, where are you getting the error at SQL-Server by create the procedure or in ASP by calling the procedure....???
0
 
LVL 4

Assisted Solution

by:BAKADY
BAKADY earned 290 total points
ID: 39234557
i found :
http://msdn.microsoft.com/en-gb/library/ms187926.aspx
http://msdn.microsoft.com/en-gb/library/ms189762.aspx

Have you a working version of the procedure? how it looks like??

regards

-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        <Author,,Name>
-- Create date: <Create Date,,>
-- Description:   <Description,,>
-- =============================================
CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName> 
      -- Add the parameters for the stored procedure here
      <@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>, 
      <@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>
AS
BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

    -- Insert statements for procedure here
      SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>
END
GO

Open in new window

0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 190 total points
ID: 39234584
First your use of DECLARE in the stored procedure creates a variable, not a parameter. This is why the parameter is not passed. The right syntax for a parameter is the one you tried but rejected because of an error. You have the choice between something that does not work and something that cause an error. Your best bet in such a situation is thus not to revert to the thing that does not work, but to try to understand what the error is.

The syntax for an integer parameter is the following, not what you used:

ALTER PROCEDURE [dbo].[usp_getPriceChart]
   @SymbolID int

I also note that there is a mismatch between your datatypes. The value you pass in an int16 (2 bytes), while your parameter type is defined as an int (4 bytes) both in the code (SqlDbType.Int) and in the stored procedure (Integer). Although this should work anyway because a 2 bytes value will fit in a 4 bytes data container, try to be careful about matching your data types to prevent possible problems.
0
 

Author Comment

by:Dovberman
ID: 39234630
USE [stockprosql]
GO
/****** Object:  StoredProcedure [dbo].[usp_getPriceChart]    Script Date: 06/10/2013 08:13:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_getPriceChart]

AS

      -- Add the parameters for the stored procedure here
      DECLARE @SymbolID int

BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
      --SET @SymbolID = 6939

SELECT QuoteDate, ClosePrice
      FROM StockHist
    WHERE SymbolID=@SymbolID AND QuoteDate <= GETDATE()
      AND QuoteDate >= DATEADD(day,-65,GETDATE())
    ORDER BY QuoteDate

      
      END

Here is the code:

 Int16 intSymbolID = 6939;

            // Try to open database and read information.
            SqlCommand cmd1 = new SqlCommand("usp_getPriceChart", pconDetail);
            cmd1.CommandType = System.Data.CommandType.StoredProcedure;
            cmd1.CommandText = "usp_getPriceChart";
            cmd1.Connection = pconDetail;
            //cmd1.Parameters.AddWithValue("@SymbolID", intSymbolID);
            cmd1.Parameters.Add("@SymbolID", SqlDbType.Int);
            cmd1.Parameters["@SymbolID"].Value = intSymbolID;

            dscWatchListChart.SelectCommand = cmd1.CommandText;

dscWatchListChart.DataBind();

aspx file:

     <asp:SqlDataSource ID="dscWatchListChart" runat="server"
         
         ConnectionString="<%$ ConnectionStrings:StockSelectSQLConnectionString %>"
         SelectCommand="usp_getPriceChart"
         SelectCommandType="StoredProcedure" >

<asp:Chart ID="ChtStock" runat="server" Height="400px" ImageLocation="~/ChartPic/" Width="750px"
        BorderlineDashStyle="Solid" BackSecondaryColor="White" BackGradientStyle="TopBottom"
        BorderlineWidth="2" EnableViewState="True" ViewStateContent="All"
        DataSourceID="dscWatchListChart">

Perhaps I should not set the DataSourceID here.
0
 

Author Comment

by:Dovberman
ID: 39234648
Runtime Error
  Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.
0
 
LVL 4

Assisted Solution

by:BAKADY
BAKADY earned 290 total points
ID: 39234650
fixed alter procedure command:
USE [stockprosql]
GO
/****** Object:  StoredProcedure [dbo].[usp_getPriceChart]    Script Date: 06/10/2013 08:13:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_getPriceChart] 
      -- Add the parameters for the stored procedure here
     @SymbolID int


AS

BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
      --SET @SymbolID = 6939

SELECT QuoteDate, ClosePrice
      FROM StockHist 
    WHERE SymbolID=@SymbolID AND QuoteDate <= GETDATE()
      AND QuoteDate >= DATEADD(day,-65,GETDATE())
    ORDER BY QuoteDate 

      
END

Open in new window

0
 

Author Comment

by:Dovberman
ID: 39234876
Same error.

I am going back to the hard coded version that worked.
0
 
LVL 4

Assisted Solution

by:BAKADY
BAKADY earned 290 total points
ID: 39234908
again:
where are you getting the error at SQL-Server by create the procedure or in ASP by calling the procedure....??? and witch error??? at line???

if the error is in asp, set some breakpoints.... please make a screenshot and/or copy and paste the error message here
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 190 total points
ID: 39234930
Your hard coded version did not work as you said. So this is definitively not the right solution. You will never be able to pass a parameter in a variable as you are trying to do with DECLARE. This is definitively wrong, so forget that direction. Try to understand why the right way to declare a parameter gives you an error instead.

Did you replace Integer by int in your parameter declaration?

ALTER PROCEDURE [dbo].[usp_getPriceChart]
   @SymbolID int
0
 
LVL 4

Assisted Solution

by:BAKADY
BAKADY earned 290 total points
ID: 39234947
can you try this???
I asume 6939 is your SymbolID.

string queryString = "CALL usp_getPriceChart(6939)";
SqlCommand command = new SqlCommand(queryString, pconDetail);
SqlDataReader reader = command.ExecuteReader();
try {
    while (reader.Read()) {
        Console.WriteLine(String.Format("{0}, {1}", reader[0], reader[1]));
    }
} finally {
    reader.Close();
}

Open in new window

0
 

Author Comment

by:Dovberman
ID: 39234994
ALTER PROCEDURE [dbo].[usp_getPriceChart]
      -- Add the parameters for the stored procedure here
@SymbolID int
AS


BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
      SET @SymbolID = 6939


Runtime Error
  Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.

Int16 intSymbolID = 6939;

            SqlCommand cmdGetChartData = new SqlCommand();
            cmdGetChartData.CommandType = CommandType.StoredProcedure;
            cmdGetChartData.CommandText = "usp_getPriceChart";

            // Add the input parameter and set its properties.
            SqlParameter parameter = new SqlParameter();
            parameter.ParameterName = "@SymbolID";
            parameter.SqlDbType = SqlDbType.Int;
            parameter.Direction = ParameterDirection.Input;
            parameter.Value = intSymbolID;
            cmdGetChartData.Parameters.Add(parameter);

            dscWatchListChart.SelectCommand = cmdGetChartData.CommandText;
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Dovberman
ID: 39235000
0
 
LVL 4

Assisted Solution

by:BAKADY
BAKADY earned 290 total points
ID: 39235045
by witch line code do you got "Runtime Error
  Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated."???

by SET @SymbolID = 6939; or
by SET NOCOUNT ON; ....

or by dscWatchListChart.SelectCommand = cmdGetChartData.CommandText;

can you find it out??? run sql in debug modus as your application, you have to find out where the error happend if your stored procedure se like this:
 
USE [stockprosql]
GO
/****** Object:  StoredProcedure [dbo].[usp_getPriceChart]    Script Date: 06/10/2013 08:13:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_getPriceChart] 
      -- Add the parameters for the stored procedure here
     @SymbolID int


AS

BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
      --SET @SymbolID = 6939

SELECT QuoteDate, ClosePrice
      FROM StockHist 
    WHERE SymbolID=@SymbolID AND QuoteDate <= GETDATE()
      AND QuoteDate >= DATEADD(day,-65,GETDATE())
    ORDER BY QuoteDate ;

END

Open in new window

0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 190 total points
ID: 39235047
This does not look like a SQL or .NET parameter error at all.

This looks like something about the configuration of control that you are using.
0
 
LVL 4

Assisted Solution

by:BAKADY
BAKADY earned 290 total points
ID: 39235061
in SQL are you able to run this???
EXEC usp_getPriceChart 6939

Open in new window

0
 

Author Comment

by:Dovberman
ID: 39235186
EXEC usp_getPriceChart 6939
and
EXEC usp_getPriceChart 6930

Both work. Therefore the Stored Procedure is properly constructed.

I will try the SqlDataReader approach.

string queryString = "CALL usp_getPriceChart(6939)";
SqlCommand command = new SqlCommand(queryString, pconDetail);
SqlDataReader reader = command.ExecuteReader();
try {
    while (reader.Read()) {
        Console.WriteLine(String.Format("{0}, {1}", reader[0], reader[1]));
    }
} finally {
    reader.Close();
}

I will try your suggestion later. I have been up all night working on this.

Thanks
0
 

Author Comment

by:Dovberman
ID: 39235218
string queryString = "CALL usp_getPriceChart(6939)";
SqlCommand command = new SqlCommand(queryString, pconDetail);
SqlDataReader reader = command.ExecuteReader();
try {
    while (reader.Read()) {
        Console.WriteLine(String.Format("{0}, {1}", reader[0], reader[1]));  Runtime error here.
    }
} finally {
    reader.Close();
}


Runtime Error
  Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 190 total points
ID: 39235248
Is pconDetail already opened when you assign it to the command? When you work with ExecuteReader and a few other commands, you need to explicitely Open and Close the SqlConnection object.
0
 

Author Comment

by:Dovberman
ID: 39235297
pconDetail was passed to the FillChart procedure.

I checked the state in a step through. It is still open.

Did I mention that this is Windows 8 and VS 2012 in ASP.NET 4.5?

I have made many changes to the same code that worked in Windows 7, VS 2008, and ASP.NET 3.5.
0
 
LVL 4

Assisted Solution

by:BAKADY
BAKADY earned 290 total points
ID: 39235456
replace
CALL usp_getPriceChart(6930)

Open in new window

With
EXEC usp_getPriceChart 6930

Open in new window

if this don't works, i don't have more ideas, why you get an error...
maybe @JamesBurger have an idea why your connection fails...
sorry
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 190 total points
ID: 39235476
"pconDetail was passed to the FillChart procedure". OK. But is the connection opened before you call ExecuteReader? Check for the value of pconDetail.State if you do not know.
0
 
LVL 4

Assisted Solution

by:BAKADY
BAKADY earned 290 total points
ID: 39235494
yes, maybe the connection will be closed after the fillchart used it, unusual but posible.

i search in the web your error message and i found something about custom error messages, see these:

http://forums.asp.net/t/1764867.aspx/1
http://sueetie.com/forum/yaf_postst626_Runtime-Error--An-exception-occurred-while-processing-your-request.aspx
http://stackoverflow.com/questions/14550911/runtime-error-even-with-error-handling

maybe can help
0
 

Author Comment

by:Dovberman
ID: 39237218
I replaced the stored procedure with a SQL Statement

     <asp:SqlDataSource ID="dscWatchListChart" runat="server"
         
         ConnectionString="<%$ ConnectionStrings:StockSelectSQLConnectionString %>"
         SelectCommand= "SELECT QuoteDate, ClosePrice
            FROM StockHist
              WHERE SymbolID=0 AND QuoteDate &gt;= DATEADD(day,-65,GETDATE())
              AND QuoteDate &lt;= GETDATE()
            ORDER BY QuoteDate ">
      </asp:SqlDataSource>

Then I referenced the SymbolID in the SQL Statement

        private void FillChart(SqlConnection pconDetail, string pstrStockSelectCon)
        {

            string strSQL = "";
            SqlCommand cmd = new SqlCommand(strSQL, pconDetail);
           
            // Get the parameter values
            string strSymbolName = "MSFT";     //grdExceptions.SelectedRow.Cells[1].Text;
            int intSymbolID = 6939; //int.Parse(grdExceptions.SelectedValue.ToString());

            strSQL = "SELECT QuoteDate, ClosePrice FROM StockHist ";
            strSQL += "WHERE SymbolID = " + intSymbolID + " AND QuoteDate <= GETDATE() ";
            strSQL += "AND QuoteDate >= DATEADD(day,-65,GETDATE()) ";
            strSQL += "ORDER BY QuoteDate ";
           
            dscWatchListChart.SelectCommand = strSQL;

                // This refreshes the chart
   
                dscWatchListChart.DataBind();

The SQL Statement works in the SQL Server Management studio

SELECT QuoteDate, ClosePrice FROM StockHist WHERE SymbolID = 6939 AND QuoteDate <= GETDATE() AND QuoteDate >= DATEADD(day,-65,GETDATE()) ORDER BY QuoteDate

Returns 38 rows :

2013-04-08 00:00:00.000      28.59
2013-04-09 00:00:00.000      29.61
2013-04-10 00:00:00.000      30.28
2013-04-11 00:00:00.000      28.93

Chart remains empty.  No errors.

Chart is not refreshed by dscWatchListChart.DataBind();

This works perfectly in VS 2008.

What is different?
0
 

Author Comment

by:Dovberman
ID: 39239295
I believe that this is a bug.  The chart control does not databind when the datasource is a parameterized SQL Statement or Stored Procedure.
0
 

Author Comment

by:Dovberman
ID: 39243423
There were several edits needed based on changes between VS 2008 and 2012.

This is what worked:

Code Behind:

private void FillChart(SqlConnection pconDetail, string pstrStockSelectCon)

        // Modifies the chart selection Select Statement
        // Sets the chart scale
        {

            string strSQL = "";
            SqlCommand cmd = new SqlCommand(strSQL, pconDetail);

            //ChtStock.DataSourceID = "dscWatchListChart"; // Use for Stored Procedure
            ChtStock.DataSourceID = "dscWatchListChart1";  // Use for SQL Statement
           
            // Set the parameter values
            string strSymbolName = "MSFT";     //grdExceptions.SelectedRow.Cells[1].Text;
            int intSymbolID = 6839; //int.Parse(grdExceptions.SelectedValue.ToString());

            strSQL = "SELECT QuoteDate AS BDate, ClosePrice AS Price FROM StockHist ";
            strSQL += "WHERE SymbolID = " + intSymbolID + " AND QuoteDate <= GETDATE() ";
            strSQL += "AND QuoteDate >= DATEADD(day,-65,GETDATE()) ";
            strSQL += "ORDER BY QuoteDate ";
           
            //2013-06-12' '2013-04-08'

            dscWatchListChart1.SelectCommand = strSQL;

            //lblStatus.Text = "";
           
            //Get the chart start date
            string strChartStartSQL = "";
            strChartStartSQL = "SELECT MIN(QuoteDate) AS ChartStartDate FROM DownLoadDates";
            string strChartStartDate = GetColValue(pconDetail, strChartStartSQL, "ChartStartDate", "String");
            strChartStartDate = DateTime.Parse(strChartStartDate).ToString("MM/dd/yyyy");

           
            // Get the parameter values
            // string strSymbolName = grdWatchList.SelectedRow.Cells[3].Text;
            // int intSymbolID = int.Parse(grdWatchList.SelectedValue.ToString());

            string strFromDate;
            strFromDate = "04/18/2013"; //lblDateFrom.Text;
           
       
            string strToDate = "05/27/2013"  ;//lblDateTo.Text;
            //int intMarketID = int.Parse(grdWatchList.SelectedRow.Cells[4].Text);

            // Set the Y axis starting value
            // at the minimum price minus 1

            string strMinCloseSQL = "";
            strMinCloseSQL = "SELECT MIN(ClosePrice) AS MinClose FROM StockHist ";
            strMinCloseSQL += "WHERE SymbolID=" + intSymbolID + " AND QuoteDate >= '" + strFromDate + "' ";
            strMinCloseSQL += " AND QuoteDate <= '" + strToDate + "' ";

            decimal decMinimum = 0;
            string strMinClose = "";
            strMinClose = GetColValue(pconDetail, strMinCloseSQL, "MinClose", "String");
            int intMinimum = 0;
            decMinimum = decimal.Parse(strMinClose);
            double dblMinimum = Convert.ToDouble(decMinimum);

            if (decMinimum > 1)
            {
                decMinimum = decimal.Parse(strMinClose);
                intMinimum = Convert.ToInt16(decMinimum);
            }

            // Set the Y axis maximum value
            // at maximum price + 1 rounded up
            string strMaxCloseSQL = "";
            strMaxCloseSQL = "SELECT Max(ClosePrice) AS MaxClose FROM StockHist ";
            strMaxCloseSQL += "WHERE SymbolID=" + intSymbolID + " AND QuoteDate >= '" + strFromDate + "' ";
            strMaxCloseSQL += " AND QuoteDate <= '" + strToDate + "' ";

            decimal decMaxClose = 0;
            string strMaxClose = "";
            strMaxClose = GetColValue(pconDetail, strMaxCloseSQL, "MaxClose", "String");
            int intMaxClose = 0;
            decMaxClose = decimal.Parse(strMaxClose);
            double dblMaxClose = Convert.ToDouble(decMaxClose);

            if (decMaxClose > 1)
            {
                decMaxClose = decimal.Parse(strMaxClose);
                intMaxClose = Convert.ToInt16(decMaxClose);
                intMaxClose = Convert.ToInt16(intMaxClose);
            }

            double dblGridInterval = ((Convert.ToDouble(intMaxClose) - Convert.ToDouble(intMinimum)) / 5);
            int intGridInterval = Convert.ToInt16(Math.Ceiling(dblGridInterval));
           
                if (decMinimum > 1)
                {
                    ChtStock.ChartAreas["Price"].AxisY.Maximum = intMaxClose + 1;
                    ChtStock.ChartAreas["Price"].AxisY.Minimum = intMinimum - 1;
                }
                else
                {
                    ChtStock.ChartAreas["Price"].AxisY.MajorGrid.Interval = .5;
                    ChtStock.ChartAreas["Price"].AxisY.Maximum = dblMinimum + .3;
                    ChtStock.ChartAreas["Price"].AxisY.Minimum = 0;
                }


                ChtStock.Series["Close"].ToolTip = "Closing Price: #VALY{C} " + " on #VALX{d} ";

                ChtStock.Titles[0].Text = strSymbolName + ":   " + strChartStartDate
                    + " to " + strToDate
                    + "   Watch List Pct Change: 4.5 since 05/22/2013"; //+ grdWatchList.SelectedRow.Cells[13].Text
                //+" since 05/22/2013"; //+ DateTime.Parse(grdWatchList.SelectedRow.Cells[6].Text).ToString("MM/dd/yyyy");

                // This refreshes the chart
               
                string strConnection = connString.ToString();
                SqlConnection conStockSelect = new SqlConnection(strConnection);

                conStockSelect.Open();
 
                ChtStock.DataBind();

            }

ASPX file:

<br /> <br />

      <asp:SqlDataSource ID="dscWatchListChart" runat="server"
         
         ConnectionString="<%$ ConnectionStrings:conStockSelect %>"
         SelectCommand="usp_getPriceChart"
         SelectCommandType="StoredProcedure" >
     
      </asp:SqlDataSource>

    <asp:SqlDataSource ID="dscWatchListChart1" runat="server"
            ConnectionString="<%$ ConnectionStrings:conStockSelect %>"
            SelectCommand= "SELECT QuoteDate AS BDate, ClosePrice AS Price
            FROM StockHist
              WHERE SymbolID=0 AND QuoteDate &gt;= DATEADD(day,-65,GETDATE())
              AND QuoteDate &lt;= GETDATE()
            ORDER BY QuoteDate "
          ProviderName ="System.Data.SqlClient"
 
            SelectCommandType="Text" >
     </asp:SqlDataSource>

===============
<asp:Chart ID="ChtStock" runat="server" Height="400px" ImageLocation="~/ChartPic/" Width="750px"
        BorderlineDashStyle="Solid" BackSecondaryColor="White" BackGradientStyle="TopBottom"
        BorderlineWidth="2" EnableViewState="True" ViewStateContent="All"  
        >
       
       <legends>
                  <asp:legend LegendStyle="Row" IsTextAutoFit="False" DockedToChartArea="Price"
                      Docking="Top" IsDockedInsideChartArea="True" Name="Default" BackColor="Transparent"
                      Font="Trebuchet MS, 8.25pt, style=Bold" Alignment="Center" MaximumAutoSize="80">
                  </asp:legend>
            </legends>

        <Titles>
            <asp:Title Name="Title1" BackColor="Yellow" BorderColor="Black"
                Font="Microsoft Sans Serif, 10pt, style=Bold" >
            </asp:Title>
        </Titles>
               
        <Series>
            <asp:Series ChartArea="Price" ChartType="Point" Legend="Default" Name="Close"
                XValueMember="BDate" YValueMembers="Price" Color="Blue" XValueType="Date">
            </asp:Series>
           
         </Series>

       
        <ChartAreas>
            <asp:ChartArea Name="Price"
                BorderColor="#646464" BorderDashStyle="Solid"
                      BackSecondaryColor="White" BackColor="#A5BFE4" ShadowColor="Transparent"
                      BackGradientStyle="TopBottom" >

                <position y="10" height="72" width="88" x="3"></position>
           
                <axisy linecolor="#646464" IsLabelAutoFit="False"
                            IsStartedFromZero="False"
                            Title = "Price" TitleFont ="Trebuchet MS, 8.25pt, style=Bold">
                              
                    <labelstyle font="Trebuchet MS, 8.25pt, style=Bold" />
                    <majorgrid linecolor="#646464" />

                        </axisy>

                <axisx linecolor="#646464" IsLabelAutoFit="True" LabelAutoFitStyle="StaggeredLabels" >
                              <labelstyle font="Trebuchet MS, 8.25pt, style=Bold" IsEndLabelVisible="True" />
                              <majorgrid linecolor="#646464" />
                        </axisx>

            </asp:ChartArea>

        </ChartAreas>
    </asp:Chart>
0
 

Author Closing Comment

by:Dovberman
ID: 39243442
Everyone contributed.

See my last comment for the solution.

Thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now