本文介绍了怀疑在sqlconnectiomn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
private double function()
{
//double d2 = a;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["stockforecasting"].ConnectionString);
con.Open();
double d1 = 0, sum = 0;
SqlDataAdapter adp = new SqlDataAdapter("select eps,pbya,normalisation from stock where pricedate between '" + txtstartdate.Text + "' AND '" + txtenddate.Text + "'", con);
DataSet ds = new DataSet();
adp.Fill(ds, "stock");
if (ds.Tables["stock"].Rows.Count - 1 > 0)
{
for (int i = 0; i < ds.Tables["stock"].Rows.Count; i++)
{
double eps = 0, pbya = 0, normalise = 0,a1=0;
for (int j = 0; j < 3; j++)
{
double d3 = 0;
string str = ds.Tables["stock"].Rows[i][j].ToString();
d1 = Convert.ToDouble(str);
if (j == 0)
{
Random rnd = new Random();
double value = rnd.NextDouble();
a1 = value;
d3 = d1 * value;
eps = d1;
SqlCommand cnd = new SqlCommand("insert into stock3(startdate,enddate,eps,weight) values('" + txtstartdate.Text + "','" + txtenddate.Text + "','" + d1 + "','" + value + "')", con);
cnd.ExecuteNonQuery();
//Console.WriteLine(eps);
//Console.WriteLine(value);
}
else if (j == 1)
{
Random rnd = new Random();
double value1 = rnd.NextDouble();
d3 = d1 * value1;
pbya = d1;
SqlCommand cnd = new SqlCommand("update stock3 set pbya='" + d1 + "',weight1='" + value1 + "' where weight='" + a1 + "' ", con);
cnd.ExecuteNonQuery();
//Console.WriteLine(pbya);
//Console.WriteLine(value1);
}
else if (j == 2)
{
Random rnd = new Random();
double value2 = rnd.NextDouble();
d3 = d1 * value2;
normalise = d1;
SqlCommand cnd = new SqlCommand("update stock3 set normalise='" + d1 + "',weight2='" + value2 + "' where weight='" + a1 + "' ", con);
cnd.ExecuteNonQuery();
//Console.WriteLine(normalise);
//Console.WriteLine(value2);
}
sum = sum + d3;
}
}
}
con.Close();
//adp.Dispose();
//ds.Reset();
return sum;
}
这是我的代码.我调用了此函数3次.它的工作.但是,如果我放置断点,则常规循环有效.如果我删除断点,它将生成相同的随机值.我不知道该怎么办
here is my code. i called this function 3 times. its working. but if i put the breakpoint , the regular loop works. if i remove the breakpoints,it generates same random values. i dont know wat to do
推荐答案
这篇关于怀疑在sqlconnectiomn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!