且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

上传后删除excel文件

更新时间:2023-12-04 20:09:16

以下代码行将达到目的:

The following lines of code will do the trick:

private void Form1_Load(object sender, EventArgs e)
{
      DataTable dtExcel = GetDataFromExcel();

     /*Implement logic to insert rows in database*/
       System.IO.File.Delete("C:\\my\\Book1.xls");

}
public DataTable GetDataFromExcel()
{
            DataTable dt = new DataTable();
            con.ConnectionString = connectionString;
            cmd.Connection = con;
            OleDbDataAdapter dap = new OleDbDataAdapter();
            dap.SelectCommand = cmd;
            dap.Fill(dt);
            return dt;
}