我使用以下代码获取no。 MS Access Db中填充的行数。但是我在打开命令时收到以下错误
public static int CountRecordsInAccess(string ResultFile)//TODO
{
string ResultFilePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + ResultFile;
string ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0" + ";Data Source=" + ResultFilePath + ";Extended Properties=Excel 12.0;Persist Security Info=False";
//Create Connection
OleDbConnection AccessConnection = new OleDbConnection(ConnectionString);
AccessConnection.Open();
//Create OleDbCommand to fetch data
OleDbCommand cmd = new OleDbCommand("SELECT COUNT (*) FROM Table1" , AccessConnection);
int rows = (int)cmd.ExecuteScalar();
AccessConnection.Close();
return rows;
}
请建议我出错的地方
答案 0 :(得分:1)
string ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0" + ";Data Source=" + ResultFilePath + ";Persist Security Info=False";