请教各位:怎样访问excel文件的数据?
我写代码如下,但总有问题,服务器通知我:无法识别的数据库格式c:\production.xlsusing System.Data.OleDb;
using System.Drawing.Imaging;
namespace WebApplication1
{
public class 数据饼图 : System.Web.UI.Page
{
int [] Num=new int[12];
string [] Mon=new string[12];
int iIndex=0;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
OleDbConnection myconn=new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data Source=c:\\production.xls;");
try
{
string str_sql="select month,number from [table1$] order by month";
OleDbCommand mycmd=new OleDbCommand(str_sql,myconn);
myconn.Open();
OleDbDataReader myreader=mycmd.ExecuteReader();
while(myreader.Read())
{
Num[iIndex]=myreader.GetInt32(1);
Mon[iIndex]=myreader.GetInt32(0).ToString()+"月";
iIndex++;
}
myreader.Close();
myconn.Close();
draw();
}
finally
{
myconn.Close();
}
}
}