日期:2014-05-17  浏览次数:21186 次

c#mschart连接sql数据库方法
求c#mschart连接sql数据库方法(winform)在图表中连接数据库,根据数据库中的参数变化图中的柱形也变化,多个柱形,谢谢

------解决方案--------------------
  string connStr = "server=localhost;database=seis_project;uid=seisprjs;pwd=seisprjs";
        SqlConnection myConn = new SqlConnection(connStr);
        string selStr = "select 帐号,count(帐号) as 次数 from pub_log_read group by 帐号 order by 帐号 desc";
        SqlCommand myCmd = myConn.CreateCommand();
        myCmd.CommandText = selStr;
        myConn.Open();
        SqlDataReader sdr = myCmd.ExecuteReader(CommandBehavior.CloseConnection);

        // Since the reader implements and IEnumerable, pass the reader directly into
        // the DataBindTable method with the name of the Column to be used as the XValue
        Chart1.Series[0].Points.DataBindXY(sdr, "帐号",sdr,"次数");

        sdr.Close();
        myConn.Close();