MrLucky Posted March 5, 2006 Posted March 5, 2006 Ok, I have this piece of code: private void CreateMostPlayedChart() { PieChart chart = new PieChart(); MySqlConnection conn = new MySqlConnection(); MySqlCommand command = new MySqlCommand(); MySqlDataReader reader; // // Build legend and value array // conn.ConnectionString = this.conn_string; try { conn.Open(); try { command.Connection = conn; command.CommandText = "SELECT COUNT(history_id) AS total_played, history_artist, history_title, history_date " + "FROM winamp_history " + "GROUP BY history_artist, history_title " + "ORDER BY total_played DESC " + "LIMIT 0, 10"; reader = command.ExecuteReader(); if(reader.HasRows) { int[] values = null; string[] legends= null; int i = 0; while(reader.Read()) { values[i] = Convert.ToInt32(reader.GetValue(reader.GetOrdinal("total_played"))); legends[i] = reader.GetValue(reader.GetOrdinal("history_artist")) + " - " + reader.GetValue(reader.GetOrdinal("history_title")); } chart.SetValues(values); chart.SetLegends(legends); chart.Render("Most played songs", "", 200, 200); System.Drawing.Image final = chart.Final; graphMostPlayed.Image = final; } } catch(MySqlException ex) { MessageBox.Show("Could not get history: " + ex.Message + "\n\n" + command.CommandText); } } catch(MySqlException ex) { MessageBox.Show("Could not connect to db: "+ ex.Message); } } As you can see, I execute this SQL query: command.CommandText = "SELECT COUNT(history_id) AS total_played, history_artist, history_title, history_date " + "FROM winamp_history " + "GROUP BY history_artist, history_title " + "ORDER BY total_played DESC " + "LIMIT 0, 10"; But my quetion is, How can I access 'total_played'? I tried to use: reader.GetValue(reader.GetOrdinal("total_played")); but that resulted in a null exception. Does anyone know how I can access that field? Quote
MrLucky Posted March 5, 2006 Author Posted March 5, 2006 Fixed this too, It was not a MySQL problem, but I didn't inited the arrays good. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.