0
我試圖導入Excel文件,我的邏輯做的是正確的:C# - 導入Excel文件,而無需知道表名稱
private void SaveFileToDB(UploadedFile uploadedFile)
{
string path = Server.MapPath("uploads/" + uploadedFile.FileName);
int currentContractId = Convert.ToInt32(Session["id"]);
string connnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";
OleDbConnection con = new OleDbConnection(connnection);
OleDbCommand command = new OleDbCommand();
DataTable dt = new DataTable();
OleDbDataAdapter myCommand = new OleDbDataAdapter(**"select * from [Sheet1$]"**, con);
myCommand.Fill(dt);
int count = 0;
//some code...
}
正如你所看到的,我硬編碼的名稱我的命令中的Excel工作表,我想知道如何繼續使其動態。