Dim fn As String = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)
Dim parth As String = Server.MapPath("~/Upload/" + fn)
Dim xlApp As New excel.Application
Dim xlBook As excel.Workbook
Dim xlSheet1 As excel.Worksheet
FileUpload1.PostedFile.SaveAs(parth)
Dim i As Integer = 1
xlBook = xlApp.Workbooks.Open(parth)
'xlBook.Application.Visible = False
xlSheet1 = xlBook.Worksheets("LoadData")
Dim dt As New System.Data.DataTable
Dim dr As System.Data.DataRow
dt.Columns.Add("locid")
dt.Columns.Add("GroupWork")
Do While Not Trim(xlSheet1.Cells.Item(i, 1).Value) = ""
dr = dt.NewRow
dr("locid") = xlSheet1.Cells.Item(i, 1).Value
dr("GroupWork") = xlSheet1.Cells.Item(i, 2).Value
dt.Rows.Add(dr)
i = i + 1
Loop
Dim buss As New CommonBusinessProcess.CommonBusinessProcess
Dim sql As String = String.Empty
For j As Integer = 0 To dt.Rows.Count - 1
sql = sql + " INSERT INTO [dbo].[tb_mapLocationWork]([locid],[Group_work_id])VALUES('" + dt.Rows(j) ("locid").ToString().Trim() + "','" + dt.Rows(j)("GroupWork").ToString().Trim() + "')"
Next
buss.ManageSQLString(sql)
dt = Nothing
xlBook.Close()
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet1)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
Dim MyFile As New FileInfo(parth)
If MyFile.Exists Then
MyFile.Delete()
End If
Tag : .NET, Excel (Excel.Application), Web (ASP.NET), VB.NET