SqlDataReader读取数据库的内容不对 请帮我看看!!!
为了测试 我的数据库中只有一列 列名为:province
列中只有4个数据分别为10、20、50、20
本来我打算用ZEDGRAPH画个饼图 但是数据库的内容读取出来时 10、20、50、20、10、20、50、20重复了一遍 不知道为什么。后来我自己测试了下把循环中的其它部分注释掉。发现while(dr.read())循环了44次(也就是下面的i输出为44)这是怎么回事呢?我的数据库中只有4个数据啊。数据库连接没有问题,我把它绑定到GRIDVIEW上也能正常显示。各位帮帮忙!!!小弟谢过...
SqlConnection myconnection = new SqlConnection("server=WIN- 42QG6PPQFE7\\SQLEXPRESS;database=asd;Integrated Security=true"); SqlCommand mycommand = new SqlCommand("SELECT * FROM locate",myconnection); myconnection.Open(); SqlDataReader dr = mycommand.ExecuteReader(); int i = 0; while(dr.Read()) { //int numbers = int.Parse(dr[0].ToString()); //string names = dr[0].ToString(); //画图 //PieItem segment = myPane.AddPieSlice(numbers, defaultColors[i], Color.White, 45f, 0, names); //segment.LabelType = PieLabelType.Value; i++; } Response.Write(i);