我上传excel文件到空间,然后对这个excel读取数据
代码如下:
HttpPostedFile excelFile = excel1.PostedFile;
string fileName = DateTime.Now.ToString("yyyy-MM-dd") + Guid.NewGuid().ToString();
if(excelFile.ContentLength >0)
{
string strExt = System.IO.Path.GetExtension(excelFile.FileName).ToLower();
string fileName1 = fileName + strExt;
if(strExt == ".xls")
{
excelFile.SaveAs(Server.MapPath("../xls/" + fileName1));//获取excel的数据
string strConn = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + Server.MapPath("../xls/" + fileName1) + ";Extended Properties=Excel 8.0"; 
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter adp = new OleDbDataAdapter("Select * from [Sheet1$]",conn);
DataSet ds = new DataSet();
adp.Fill(ds,"Book1");//给一个DataGrid赋值
ExlDataGrid.DataSource = ds.Tables["Book1"].DefaultView;
ExlDataGrid.DataBind();
}这些都很成功,但把excel数据往sql数据库加时就有问题了,当我上传的excel的数据多于5列时,就出错
错误信息如下:System.IndexOutOfRangeException: Index was outside the bounds of the array.
求救啊!!!什么问题啊!!!