C#winform中如何将连接的sql数据库中某一列float数据提取保存到某一个int型数组中?
Point[]curvePoints=newPoint[2000];//建立点集intnum=0;intx1=10;stringstrConn="DataSource=....
Point[] curvePoints = new Point[2000];//建立点集
int num = 0;
int x1 = 10;
string strConn = "Data Source=.;Initial Catalog=electric2;User ID=sa;pwd=123;";
string sql = "select Voltage from Table_1 order by DateTime";//列名为Voltage
SqlConnection conn = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand(sql,conn);
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
curvePoints[num] = new Point(x1, Convert.ToInt32(sdr[num]));//填充坐标
num = +1;
x1 = +30;
}
sdr.Close();
conn.Close();
这么写不知道对不对? 展开
int num = 0;
int x1 = 10;
string strConn = "Data Source=.;Initial Catalog=electric2;User ID=sa;pwd=123;";
string sql = "select Voltage from Table_1 order by DateTime";//列名为Voltage
SqlConnection conn = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand(sql,conn);
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
curvePoints[num] = new Point(x1, Convert.ToInt32(sdr[num]));//填充坐标
num = +1;
x1 = +30;
}
sdr.Close();
conn.Close();
这么写不知道对不对? 展开
2个回答
展开全部
num=+1?
"select Voltage from Table_1 order by DateTime" 查询是只有一列呀?
var tmp = Convert.ToInt32(sdr[“Voltage”];
curvePoints[num] = new Point(x1,tmp))?
可以断点看看tmp的值
"select Voltage from Table_1 order by DateTime" 查询是只有一列呀?
var tmp = Convert.ToInt32(sdr[“Voltage”];
curvePoints[num] = new Point(x1,tmp))?
可以断点看看tmp的值
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
curvePoints[num] = new Point(x1, Convert.ToInt32(sdr[0]));
更多追问追答
追问
curvePoints[num] = new Point(x1, Convert.ToInt32(sdr[0]));//填充坐标
可是之后添加如此代码时弹出的messagebox里的值却与所想要的值不对应啊: MessageBox.Show(Convert.ToInt32(sdr[0]).ToString());
注:数据取出时是依次取出,并且依次放入点集里面的啊
追答
每行read出来的只有1列啊,就应该是sdr[0]啊,这个0表示这行数据的第几列,另外,你的float数据做强制转化的话是取整的吧,这个也得注意啊
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询