0
使用vb.net將excel文件值寫入記事本。在我的代碼中使用oledb提供程序打開excel文件。但在打開excel文件時出現錯誤。該文件命名爲「phone data.xlsx」。存儲在我的系統桌面上。使用文件上傳控制來獲取該文件。使用oledb提供商使用vb.net打開excel文件
my code
-------
Dim pathToCheck As String = filename
If System.IO.File.Exists(pathToCheck) = "True" Then
IO.File.Delete(filename)
End If
Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter("D:\modellog.txt", True, System.Text.Encoding.UTF8)
If FileUpload2.HasFile Then
TextBox1.Text = FileUpload2.FileName
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim Ds As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Try
MyConnection = New System.Data.OleDb.OleDbConnection(("provider=Microsoft.ACE.OLEDB.12.0; " + ("data source=" _
+ (TextBox1.Text + ("; " + "Extended Properties=Excel 12.0;")))))
MyCommand = New System.Data.OleDb.OleDbDataAdapter _
("select * from [Sheet1$]", MyConnection)
Ds = New System.Data.DataSet
MyCommand.Fill(Ds)
error
-----
The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data.