SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Assign variable to query in .net

    Hi all, I hope your appreciated help.

    This is partial codebehind of my page net for Chart Controls.

    My problem is the `Legend` of the chart.

    I need see in the same `Legend` the value of query alias `q` though this is not published as a column/series of values in the chart.

    With this code I see the attachment image: `output q` but I need see `output 13%`

    Can you help me?

    Thank you
    Code:
    String strQuery = " SELECT " +
                              " tPreviousYear" +
                              ",Region " +
                              ",CONCAT(Perc,'%') As `q` " +
                              " FROM tbl_m; ";
    
           OdbcConnection myConnectionString = 
           new odbcConnection(
           ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
           myConnectionString.Open();
           
           OdbcCommand objCmd = new OdbcCommand(strQuery, myConnectionString);
           objCmd.CommandType = CommandType.Text;
           objCmd.CommandText = strQuery;
        
           Chart1.DataSource = objCmd.ExecuteReader(); 
    ...
    
           String top = "q";
           LegendItem newItem = new LegendItem();
           newItem.ImageStyle = LegendImageStyle.Marker;
           newItem.MarkerStyle = MarkerStyle.Diamond;
           newItem.Cells.Add(LegendCellType.SeriesSymbol, "", ContentAlignment.MiddleLeft);
           newItem.Cells.Add(LegendCellType.Text, "output", ContentAlignment.MiddleLeft);
           newItem.Cells[1].CellSpan = 2;
           newItem.Cells.Add(LegendCellType.Text, "", ContentAlignment.MiddleLeft);
           newItem.Cells.Add(LegendCellType.Text, top, ContentAlignment.MiddleLeft);
           Chart1.Legends[0].CustomItems.Add(newItem);
    Attached Images Attached Images
    Thanks you very much for your help
    I'm really happy for your quickly answer.
    Good bye

  2. #2
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well... I try this solution with reader method, but I have this error:
    No data exists for the row/column.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidOperationException: No data exists for the row/column.

    Source Error:

    Line 688:
    Line 690: String top = reader["VarPerc"].ToString();
    Line 691: reader.Dispose();
    Line 692: reader.Close();
    thanks for your time.
    Your help would be very appreciated
    PHP Code:
    String myQuery " SELECT " +
                              
    " tPreviousYear" +
                              
    ",Region " +
                              
    ",VarPerc " +
                              
    " FROM tbl_m; ";

           
    OdbcConnection myConnectionString 
           new 
    odbcConnection(
           
    ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
           
    myConnectionString.Open();
           
           
    OdbcCommand objCmd = new OdbcCommand(myQuerymyConnectionString);
           
    objCmd.CommandType CommandType.Text;
           
    objCmd.CommandText myQuery;
        
           
    OdbcDataReader reader objCmd.ExecuteReader();

           
    Chart1.DataSource reader//CHART NOT GENERATE
           
    Chart1.DataBind();

           
    //Chart1.DataSource = objCmd.ExecuteReader(); //CHART GENERATE
           
           
    while (reader.Read())

               
    Response.Write(reader["VarPerc"].ToString()); //PRINT CORRECT OUTPUT -59


           
    Chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination 0;
           
    Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D false;
           
    Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Angle 0;
           
    Chart1.ChartAreas["ChartArea1"].AxisX.IsLabelAutoFit false;

           .......

           
    DateTime dateTime = new DateTime(DateTime.Now.AddYears(-1).Year12DateTime.Now.Day);
           
    string s3 dateTime.ToString("MMM yyy");
           
    Chart1.Series.Add(s3);
           
    Chart1.Series[s3].LabelFormat "0.#";
           
    Chart1.Series[s3].XValueMember "Region";
           
    Chart1.Series[s3].YValueMembers "tPreviousYear";
           
    Chart1.Series[s3].ChartType SeriesChartType.Column;
           
    Chart1.Series[s3]["PointWidth"] = "0.85";
           
    Chart1.Series[s3].IsValueShownAsLabel true;
           
    Chart1.Series[s3]["PixelPointDepth"] = "1.0";
           
    Chart1.Series[s3]["DrawingStyle"] = "Cylinder";
           
    Chart1.Series[s3].Font = new System.Drawing.Font("Verdana"9FontStyle.Bold);
           
    Chart1.Series[s3].LabelForeColor System.Drawing.Color.FromArgb(00128);
           
    Chart1.Series[s3]["LabelStyle"] = "Top";
           
    Chart1.Series[s3].Color System.Drawing.Color.FromArgb(00205);    

           
    Chart1.Legends.Add(new Legend(s3));
           
    Chart1.Legends[s3].BackGradientStyle GradientStyle.DiagonalLeft;
           
    Chart1.Legends[s3].BorderColor Color.Black;
           
    Chart1.Legends[s3].BorderWidth 2;
           
    Chart1.Legends[s3].BorderDashStyle ChartDashStyle.Solid;
           
    Chart1.Legends[s3].ShadowOffset 2;
           
    Chart1.Legends[s3].Docking Docking.Bottom;
           
    Chart1.Legends[s3].Alignment System.Drawing.StringAlignment.Center;
           
    Chart1.Legends[s3].Font = new System.Drawing.Font("Verdana"12FontStyle.Bold);
           
    Chart1.Series[s3].Legend s3;   
      
           
    String top reader["VarPerc"].ToString(); //LINE OF ERROR: No data exists for the row/column.
           
    LegendItem newItem = new LegendItem();
           
    newItem.ImageStyle LegendImageStyle.Marker;
           
    newItem.MarkerStyle MarkerStyle.Diamond;
           
    newItem.Cells.Add(LegendCellType.SeriesSymbol""ContentAlignment.MiddleLeft);
           
    newItem.Cells.Add(LegendCellType.Text"top"ContentAlignment.MiddleLeft);
           
    newItem.Cells[1].CellSpan 2;
           
    newItem.Cells.Add(LegendCellType.Text""ContentAlignment.MiddleLeft);
           
    newItem.Cells.Add(LegendCellType.TexttopContentAlignment.MiddleLeft);
           
    Chart1.Legends[0].CustomItems.Add(newItem);  

           
    reader.Dispose();
           
    reader.Close();

           
    objCmd.Dispose();
           
    objCmd.Cancel();              
                               
           
    myConnectionString.Dispose(); 
           
    myConnectionString.Close(); 
    Thanks you very much for your help
    I'm really happy for your quickly answer.
    Good bye


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •