protected void Page_Load(object sender, EventArgs e)
{
Series series1 = new Series();
Series series2 = new Series();
List<ChartSqlData> data = new List<ChartSqlData>();
string connectionString = null;
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet dataset = new DataSet();
connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;User Instance=false;Connect Timeout=100;";
SqlConnection con = new SqlConnection(connectionString);
con.Open();
string command2 = "SELECT * FROM [Products] WHERE UnitPrice < 10";
SqlCommand cmd1 = new SqlCommand(command2, con);
adapter.SelectCommand = cmd1;
adapter.Fill(dataset);
for (var i = 0; i < dataset.Tables[0].Rows.Count; i++)
{
string x1 = Convert.ToString(dataset.Tables[0].Rows[i]["ProductName"]);
double y1 = Convert.ToDouble(dataset.Tables[0].Rows[i]["UnitPrice"]);
double y2 = Convert.ToDouble(dataset.Tables[0].Rows[i]["UnitsInStock"]);
data.Add(new ChartSqlData(x1, y1, y2));
}
this.Chart1.DataSource = data;
this.Chart1.DataBind();
}
} |