我的最終目標是從.xlsx文件檢索數據並將它們加載到.mdb(Microsoft Access)文件中。我的代碼現在是這樣的:使用OleDb(C#)從xlsx檢索數據,如何獲取xlsx中的行數?
String fileName = "1.xlsx";
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + fileName + ";" + ";Extended Properties=\"Excel 12.0;HDR=YES;IMEX=1\"");
conn.Open();
DataTable dtSheetName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
string cmdText = "SELECT * FROM [sheet1$A3:B3]";
DataSet ds;
using (OleDbCommand cmd = new OleDbCommand(cmdText))
{
cmd.Connection = conn;
OleDbDataAdapter adpt = new OleDbDataAdapter(cmd);
ds = new DataSet();
adpt.Fill(ds, "sheet1");
}
但是,這是當我知道表中有多少行。如果我不知道這些信息怎麼辦?我能以某種方式知道表格中有多少行嗎?