|
[C#]
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = null;
// Create sql adapter
SqlDataAdapter adapter = new SqlDataAdapter();
// create data set for storing the data
DataSet dataset = new DataSet();
// Getting connection string from database
connectionString = @"Data Source=SYNCLAPN7425\SQLEXPRESS;Initial Catalog=master;Integrated Security=True";
SqlConnection con = new SqlConnection(connectionString);
// open the connection
con.Open();
// Create the sql command
SqlCommand cmd = new SqlCommand();
// provide the command
cmd.CommandText = "INSERT INTO Table_1(xName, yName,yName1,yName2) VALUES(@xName, @yName,@yName1,@yName2)";
Random r = new Random();
string command2 = "select * from Table_1";
SqlCommand cmd1 = new SqlCommand(command2, con);
adapter.SelectCommand = cmd1;
// Data set added into the sql adapter
adapter.Fill(dataset);
int count = dataset.Tables[0].Rows.Count;
double value = Double.Parse(dataset.Tables[0].Rows[count - 1].ItemArray[0].ToString());
// Added the data into table
for (double i = (value + 1); i <= (value + 100); i++)
{
cmd.Parameters.Add("@xName", SqlDbType.VarChar).Value = i;
cmd.Parameters.Add("@yName", SqlDbType.VarChar).Value = r.Next(1, 30);
cmd.Parameters.Add("@yName1", SqlDbType.VarChar).Value = r.Next(30, 60);
cmd.Parameters.Add("@yName2", SqlDbType.VarChar).Value = r.Next(60, 100);
cmd.Connection = con;
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
adapter.SelectCommand = cmd1;
adapter.Fill(dataset);
List<ChartData> data = new List<ChartData>();
bool process = true;
// Getting the data from the sql adapter
for (int j = 0; j < dataset.Tables[0].Rows.Count; j++)
{
string x = dataset.Tables[0].Rows[j].ItemArray[0].ToString();
process = (data.Any(z => z.Xvalue == x)) ? false : true;
if (process)
{
double yValue1 = Double.Parse(dataset.Tables[0].Rows[j].ItemArray[1].ToString());
double yValue2 = Double.Parse(dataset.Tables[0].Rows[j].ItemArray[2].ToString());
double yValue3 = Double.Parse(dataset.Tables[0].Rows[j].ItemArray[3].ToString());
data.Add(new ChartData(x, yValue1,yValue2,yValue3));
}
}
// Close the sql connection
con.Close();
// Binding the data
this.Chart1.DataSource = data;
this.Chart1.DataBind();
} |
This is working fine for me, thank you!
kind regards
Zack