0
public partial class Piechart : System.Web.UI.Page
{
    private decimal total = 0; // course total
    private decimal registered = 0;
    private decimal regAttend = 0;
    private decimal nRegAttend = 0;
    private int regPer = 0;
    private int regToTotalPer = 0;
    private int nRegPer = 0;
    private int angle = 0;
    private int angle2 = 0;
    private int angle3 = 0;
    private int parTotal = 0;
    //const string G = "SELECT DISTINCT COUNT(Grouping) from Attendance";
   // SqlConnection c = new SqlConnection(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=PSeminar;Integrated Security=true;Trusted_Connection=Yes;MultipleActiveResultSets=true");
    //SqlCommand Command = new SqlCommand(G);


    private string[] Status = new string[2] { "Attend", "Didn't Attend" };
    private string[] Course = new string[] {//items from database};

I want to use a sql statement to call a list of items and store inside the above array. I am doing this as previously the items in the array were hardcoded. Now I want to retrieve it from the database, as whenever there is a new item, a new pie chart will be drawn automatically.

5
  • Which items of database you want to store into an array? Commented Sep 21, 2011 at 3:11
  • why store it in an array just store it as a List<> and capture the datarow Commented Sep 21, 2011 at 3:14
  • @Avd items are from the above select statement."//const string g..." Commented Sep 21, 2011 at 3:14
  • How are you hitting the database? Are you locked into something specific, such as ADO.Net, or can you use Entity Framework, etc? Commented Sep 21, 2011 at 3:22
  • @mtaza we are using "sql connection to call the database", as stated above. the database we are using is sql server. And i am also using ASP.net Commented Sep 21, 2011 at 3:28

1 Answer 1

1

here's a way to do this with an ArrayList

ArrayList Course = new ArrayList();
const string query = "SELECT DISTINCT COUNT(Grouping) from Attendance";
const string connectionString = @"Data Source=localhost\SQLEXPRESS;Initial Catalog=PSeminar;Integrated Security=true;Trusted_Connection=Yes;MultipleActiveResultSets=true";
using (SqlConnection cn = new SqlConnection(connectionString))
{
    using (SqlCommand cm = new SqlCommand(query, cn))
    {
        cn.Open();
        SqlDataReader reader = cm.ExecuteReader();
        while (reader.Read())
        {
            Course.Add(reader.GetString(0));
        }
    }
}

//Course.ToArray(); // <-- cast to string array object do use in the pie chart
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.