开发环境 vs2010 myConn.Open();打不开 是什么问题 如果用vs2005是没有问题的下面是将excel 数据导入系统
public DataSet ReadFromExcelToDataSet(string fileName, string tableName)
{
string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" + fileName + "';Extended Properties='Excel 8.0;IMEX=1'";
OleDbConnection myConn = new OleDbConnection(strCon);
myConn.Open();
string strCom = " SELECT * FROM [" + tableName + "$] ";
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet, "[" + tableName + "$]");
myConn.Close();
return myDataSet;
}
public DataSet ReadFromExcelToDataSet(string fileName, string tableName)
{
string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" + fileName + "';Extended Properties='Excel 8.0;IMEX=1'";
OleDbConnection myConn = new OleDbConnection(strCon);
myConn.Open();
string strCom = " SELECT * FROM [" + tableName + "$] ";
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet, "[" + tableName + "$]");
myConn.Close();
return myDataSet;
}
string fileName = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
fileName = openFileDialog1.FileName;
}
else
{
return;
}
应该没有问题的 在vs2005上面可以读到数据的
去掉引号试试另一种方法:string strCon = " Provider = Microsoft.Ace.OLEDB.12.0; Data Source = " + fileName + ";Extended Properties=Excel 12.0;";
试过了 好像不行 Excel 12.0
这种应该可以吧