读书人

c#mschart连接sql数据库步骤

发布时间: 2014-01-03 00:30:09 作者: rapoo

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();

读书人网 >C#

热点推荐