Pagina 2 di 2 primaprima 1 2
Visualizzazione dei risultati da 11 a 13 su 13
  1. #11
    Utente di HTML.it L'avatar di orcim
    Registrato dal
    May 2003
    Messaggi
    1,692
    Grazie mille, ma non riesco a farlo funzionare... scusa ma sono un imbranato...

    Con le ultime modifiche adesso l'errore è Nessun dato esistente per la riga/colonna in corrispondenza della riga:
    codice:
    String top = reader["VarPerc"].ToString();
    E nel momento in cui sostituisco la riga
    codice:
    Chart1.DataSource = objCmd.ExecuteReader();
    con
    codice:
           Chart1.DataSource = reader;
           Chart1.DataBind();
    Non si genera più il grafico dinamico...

    codice:
    String myQuery = " SELECT tNome, " +
                             " VariazionePercentuale As VarPerc " +                         
                             " FROM tbl_m " +
                             " WHERE " +
                             " tNome LIKE '%Pippo%'; ";
    
           OdbcConnection myConnectionString = 
           new OdbcConnection(
           ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
           myConnectionString.Open();
           
           OdbcCommand objCmd = new OdbcCommand(myQuery, myConnectionString);
           objCmd.Prepare();
           objCmd.CommandType = CommandType.Text;
           objCmd.CommandText = myQuery;
    
           OdbcDataReader reader = objCmd.ExecuteReader();
    
           Chart1.DataSource = reader;
           Chart1.DataBind();
           
           while (reader.Read())
               Response.Write(reader["VarPerc"].ToString());
      
           String top = reader["VarPerc"].ToString();
           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.Text, top, ContentAlignment.MiddleLeft);
           Chart1.Legends[0].CustomItems.Add(newItem);  
    
           reader.Dispose();
           reader.Close();
    
           objCmd.Dispose();
           objCmd.Cancel();              
                               
           myConnectionString.Dispose(); 
           myConnectionString.Close();
    "Ubi Maior, Minor Cessat"
    Domandare è lecito, rispondere è cortesia...
    A tutti è dovuta una risposta, comunque...

    “Dio gradisce molto di più le bestemmie dell’uomo disperato che non le lodi del benpensante la domenica mattina durante il culto“ Martin Lutero

  2. #12
    Moderatore di ASP.net L'avatar di djciko
    Registrato dal
    Nov 2002
    Messaggi
    6,887
    Allora, due cose:

    1
    Prima di leggere un valore contenuto in un datareader devi farlo avanzare con la "testina" di lettura interna, effettuando una -- read --. Oppure usare il valore desiderato in una while che cicla il suo contenuto (la while scritta in quel modo effettua implicitamente la read, testando la fine degli items).

    >>>> Atrimenti e' fermo alla posizione -1.

    Nel tuo codice comunque e' solo questione di ordine, in alternativa dovresti chiudere il reader ed effettuare di nuovo la execute. Prima ti generava un errore perche' tentavi di ri-eseguire una execute con il reader associato ancora aperto.

    2
    Chart1 che cos'e' ?

  3. #13
    Utente di HTML.it L'avatar di orcim
    Registrato dal
    May 2003
    Messaggi
    1,692
    Grazie ancora una volta.

    >>>> Atrimenti e' fermo alla posizione -1.
    La posizione -1 corrisponde al valore restituito a video -59con il Response.Write(reader["VarPerc"].ToString()); ?
    Se fosse così va bene perchè devo prendere solo quello restituito dalla myQuery, che è solo uno,

    2
    Chart1 che cos'e' ?
    Chart1 è la generazione di un grafico tramite la classe chart controls per .NET Framework.

    codice:
    String myQuery = " SELECT tNome, tAnnoPrecedente, " +
                             " VariazionePercentuale As VarPerc " +                         
                             " FROM tbl_m " +
                             " WHERE " +
                             " tNome LIKE '%Pippo%'; ";
    
           OdbcConnection myConnectionString = 
           new OdbcConnection(
           ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
           myConnectionString.Open();
           
           OdbcCommand objCmd = new OdbcCommand(myQuery, myConnectionString);
           objCmd.Prepare();
           objCmd.CommandType = CommandType.Text;
           objCmd.CommandText = myQuery;
    
           OdbcDataReader reader = objCmd.ExecuteReader();
    
           Chart1.DataSource = reader; //COSì NON SI GENERA IL GRAFICO
           Chart1.DataBind();
    
           //Chart1.DataSource = objCmd.ExecuteReader(); //COSì SI GENERA IL GRAFICO
           
           while (reader.Read())
               Response.Write(reader["VarPerc"].ToString());
    
    
    
           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).Year, 12, DateTime.Now.Day);
           string s3 = dateTime.ToString("MMM yyy");
           Chart1.Series.Add(s3);
           Chart1.Series[s3].LabelFormat = "0.#";
           Chart1.Series[s3].XValueMember = "tNome";
           Chart1.Series[s3].YValueMembers = "tAnnoPrecedente";
           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", 9, FontStyle.Bold);
           Chart1.Series[s3].LabelForeColor = System.Drawing.Color.FromArgb(0, 0, 128);
           Chart1.Series[s3]["LabelStyle"] = "Top";
           Chart1.Series[s3].Color = System.Drawing.Color.FromArgb(0, 0, 205);    
    
           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", 12, FontStyle.Bold);
           Chart1.Series[s3].Legend = s3;   
      
           String top = reader["VarPerc"].ToString();
           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.Text, top, ContentAlignment.MiddleLeft);
           Chart1.Legends[0].CustomItems.Add(newItem);  
    
           reader.Dispose();
           reader.Close();
    
           objCmd.Dispose();
           objCmd.Cancel();              
                               
           myConnectionString.Dispose(); 
           myConnectionString.Close();
    "Ubi Maior, Minor Cessat"
    Domandare è lecito, rispondere è cortesia...
    A tutti è dovuta una risposta, comunque...

    “Dio gradisce molto di più le bestemmie dell’uomo disperato che non le lodi del benpensante la domenica mattina durante il culto“ Martin Lutero

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.