hi
In my application i want to import table from Access to Excel.I have include Microsoft Web Browser to display the excel sheet .When i am running the application.It display the sheet.But One error is pop up"The file can not access,it being used by another process"
Can anyone give the sol.here is my code
Try
Dim excel As New Excel.ApplicationClass
Dim wBook As Excel.Workbook
Dim wSheet As Excel.Worksheet
wBook = excel.Workbooks.Add()
wSheet = wBook.ActiveSheet()
filltemp()
Cmd.CommandType = CommandType.Text
'Cmd.CommandText = "Select * from SalRpt_temp"
Cmd.CommandText = "SELECT a.srno as Srno,a.ename as 'Name Of Employee',a.pdays as 'Present Day',a.desig as Designation ,a.bs as Basic,a.dp as DP,a.total as Total,a.hra as HRA,a.cla as CLA,a.ta as TA,a.npa as NPA,a.other as'Other Allowance',a.tal as 'Total Allowance',a.net as 'Net Claim',a.pt as 'PTax',a.it as 'Income Tax',a.sal as 'SalAdv',a.pf as PF,a.lic as LIC,a.bank as 'Bank Recov',a.tdeduct as 'Total Deduction',a.netsal as 'Net Salary' FROM SalRpt_temp a"
Cmd.Connection = con
adp.SelectCommand = Cmd
adp.Fill(ds)
Dim dt As System.Data.DataTable = ds.Tables(0)
Dim dc As System.Data.DataColumn
Dim dr As System.Data.DataRow
Dim colIndex As Integer = 0
Dim rowIndex As Integer = 1
For Each dc In dt.Columns
colIndex = colIndex + 1
excel.Cells(1, colIndex) = dc.ColumnName
Next
For Each dr In dt.Rows
rowIndex = rowIndex + 1
colIndex = 0
For Each dc In dt.Columns
colIndex = colIndex + 1
excel.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)
Next
Next
'AxWebBrowser1.Navigate("G:\Salary Package\salary.xls")
wSheet.Columns.AutoFit()
Dim strFileName As String = "G:\Salary Package\salary.xls"
AxWebBrowser1.Navigate(strFileName)
Dim blnFileOpen As Boolean = False
Try
Dim fileTemp As System.IO.FileStream = System.IO.File.OpenWrite(strFileName)
fileTemp.Close()
Catch ex As Exception
blnFileOpen = False
End Try
If System.IO.File.Exists(strFileName) Then
System.IO.File.Delete(strFileName)
End If
wBook.SaveAs(strFileName)
excel.Workbooks.Open(strFileName)
excel.Visible = True
Catch ex As Exception
con.Close()
MsgBox(ex.Message)
End Try
plz help me.My technology is vb.net2003 + ms access