当前位置:编程学习 > C#/ASP.NET >>

asp 中怎么用MSchart 连接MYSQL数据库

我在网上看过好多MSCHART连接数据库的,可是就是没有和MYSQL连接的,因为刚接触这个MSCHART,还不太了解,谁能帮我写一下呢,比如数据库中中abc表里只有“mouth”“money”,做一个简单的月份花销直方图

 Chart1.Width = 600;                      //图表宽度 
    Chart1.Height = 400;                     //图表高度 
                //图表背景色 
    Chart1.Titles.Add("花销");                //图表标题 
        
        
        
              DataSet ds = new DataSet();
        string sql = "select month,Allcount from abc";
        string constr = "server=localhost;User Id=root;password=root;Database=bnlbj;";
        MySqlConnection con = new MySqlConnection(constr);
        con.Open();
        try
        {
            MySqlDataAdapter Da = new MySqlDataAdapter();
            Da.SelectCommand = new MySqlCommand(sql, con);
            Da.Fill(ds);
             Chart1.DataSource = Da;
            
       //     MySqlDataReader read= con.Database;
       //    Chart1.DataBindTable(read,"month");
        //   read.Close()
              con.Close();

        }
        catch (Exception ex)
        {
        }
        Chart1.Series[0].XValueMember = "month";
       Chart1.Series[0].YValueMembers = "Allcount";
这是我自己写的,可是不知道哪里不合适,拜托了
       --------------------编程问答-------------------- --------------------编程问答-------------------- 先装MYSQL的ODBC驱动
http://www.mysql.com/downloads/api-myodbc-2.50.html
  
用DSN
  先建一个名为mysql的数据源,然后
  strConnection = "dsn=mysql;driver={myodbd driver};server=localhost;uid=root;pwd=;database=密码"  --------------------编程问答-------------------- 将Table转换成DataView
Da.Fill(ds);
DataView myView = new DataView(ds.Tables[0]);
Chart1.Series["Series1"].Points.DataBindXY(myView, "mouth", myView, "money");

将你代码以下删了! --------------------编程问答--------------------
引用 3 楼 koukoujiayi 的回复:
将Table转换成DataView
Da.Fill(ds);
DataView myView = new DataView(ds.Tables[0]);
Chart1.Series["Series1"].Points.DataBindXY(myView, "mouth", myView, "money");

将你代码以下删了!

谢谢你,我改了一小部分,可以了, --------------------编程问答-------------------- 不错,非常有用的
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,