【发布时间】:2014-10-30 08:18:25
【问题描述】:
我尝试读取 CSV 数据并将其显示在 Visual Studio 的图表中。我收到一个 SystemArgument.Exception,它告诉我他找不到名为“Date”的列。
我的代码如下:
private void button1_Click_1(object sender, EventArgs e)
{
string file = "test.csv";
string dir = "C:\\Main";
string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
dir + ";Extended Properties=\"Text;HDR=No;FMT=Delimited\"";
OleDbConnection myConnection = new OleDbConnection(ConStr);
string mySelectQuery = "Select * from " + file;
OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);
myCommand.Connection.Open();
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
chart1.Series["Test"].Points.DataBindXY(myReader, "Date",myReader,"Value");
chart1.Series["Test"].ChartType = SeriesChartType.Line;
myReader.Close();
myConnection.Close();
}
怎么了?我希望有人可以帮助我...... .Csv 数据是: 两列 - 第一列第一行是日期 第二列第一行是值 第一列中的行看起来像 01.04.2010 - 第二列中的行看起来像 234.567
【问题讨论】: