为了测试 我的数据库中只有一列 列名为:province
列中只有4个数据分别为10、20、50、20
本来我打算用ZEDGRAPH画个饼图 但是数据库的内容读取出来时 10、20、50、20、10、20、50、20重复了一遍 不知道为什么。后来我自己测试了下把循环中的其它部分注释掉。发现while(dr.read())循环了44次(也就是下面的i输出为44)这是怎么回事呢?我的数据库中只有4个数据啊。数据库连接没有问题,我把它绑定到GRIDVIEW上也能正常显示。各位帮帮忙!!!小弟谢过...
- C# code
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);
------解决方案--------------------------------------------------------
没问题啊
你在数据库中查询 SELECT * FROM locate 看看有多小条数据
------解决方案--------------------------------------------------------
是不是重复加载了
加
if(!IsPostBack)
{
this.ZedGraphWeb1.RenderGraph += new ZedGraph....
}
------解决方案--------------------------------------------------------
好像也不是直接写在pageload里面
应该是InitializeComponent在这里面写
private void InnitializeComponent()
{
this.ZedGraphWeb1.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(ZedGraphWeb1_RenderGraph);
}
试试。