http://blog.csdn.net/pitt_xiong/article/details/7921358 这个是连接数据库的。
你参考下修改

解决方案 »

  1.   

     // Access database
                //System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm)this.ParentForm;
                string fileNameString =Application.StartupPath+ "\\data\\chartdata.mdb";            // initialize a connection string
                string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;            // define the database query
                string mySelectQuery = "SELECT * FROM REPS;";            // create a database connection object using the connection string
                OleDbConnection myConnection = new OleDbConnection(myConnectionString);            // create a database command on the connection using query
                OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);            // open the connection
                myCommand.Connection.Open();            // Initializes a new instance of the OleDbDataAdapter class
                OleDbDataAdapter custDA = new OleDbDataAdapter();
                custDA.SelectCommand = myCommand;            // Initializes a new instance of the DataSet class
                DataSet custDS = new DataSet();            // Adds rows in the DataSet
                custDA.Fill(custDS, "Customers");            // Initializes a new instance of the DataView class
                DataView firstView = new DataView(custDS.Tables[0]);            // since the DataView implements and IEnumerable, pass the reader directly into
                // the DataBind method with the name of the Columns selected in the query
                chart1.Series["Default"].Points.DataBindXY(firstView, "Name", firstView, "Sales");            // Closes the connection to the data source. This is the preferred 
                // method of closing any open connection.
                myCommand.Connection.Close();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                // TODO: 这行代码将数据加载到表“dataDataSet.radial”中。您可以根据需要移动或移除它。
                this.radialTableAdapter.Fill(this.dataDataSet.radial);
                // TODO: 这行代码将数据加载到表“dataDataSet1.radial”中。您可以根据需要移动或移除它。
                this.radialTableAdapter1.Fill(this.dataDataSet1.radial);
                // TODO: 这行代码将数据加载到表“dataDataSet.radial”中。您可以根据需要移动或移除它。
                //this.radialTableAdapter.Fill(this.dataDataSet.radial);
      

  2.   

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