Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If FileUpload1.HasFile Then
Try
' alter path for your project
FileUpload1.SaveAs(Server.MapPath("~/ExcelImport.xls"))
Label1.Text = "Upload File Name: " & _
FileUpload1.PostedFile.FileName & "<br>" & _
"Type: " & _
FileUpload1.PostedFile.ContentType & _
" File Size: " & _
FileUpload1.PostedFile.ContentLength & " kb<br>"
Catch ex As Exception
Label1.Text = "Error: " & ex.Message.ToString
End Try
Else
Label1.Text = "Please select a file to upload."
End If
End Sub
Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click
Try
Dim DataAdapter As New OleDbDataAdapter()
' retrieve the Select command for the Spreadsheet
DataAdapter.SelectCommand = ExcelConnection()
' Create a DataSet
Dim ds As New DataSet()
' Populate the DataSet with the spreadsheet worksheet data
DataAdapter.Fill(ds, "T_HQ_BADGE")
ds.Tables(0).TableName = "T_HQ_BADGE"
ds.Merge(ds.Tables("T_HQ_BADGE"))
Catch ex As Exception
Label1.Text = "Error: " & ex.Message.ToString
End Try
'For i = 0 To ds.Tables("HQ_BADGE").Rows.Count - 1 Step i + 1
' Dim Query As String = "Insert into T_HQ_BADGE (HQBD_PLAZANO,HQBD_BADGENO,HQBD_GROUPLEVEL,HQBD_BADGENAME,HQBD_PASSWORD,HQBD_MFGNO) values('" + ds.Tables("HQ_BADGE").(i)("HQBD_PLAZANO").tostring() + "','" + objDataSet.Tables("HQ_BADGE").(i)("HQBD_BADGENO").tostring() + "','" + objDataSet.Tables("HQ_BADGE").(i)("HQBD_PLAZANO").tostring() + "','" + objDataSet.Tables("HQ_BADGE").i("HQBD_PLAZANO").tostring() + "','" + objDataSet.Tables("T_HQ_BADGE").(i)("HQBD_GROUPLEVEL").tostring() + "','" + objDataSet.Tables("HQ_BADGE").(i)("HQBD_BADGENAME").tostring() + "','" + objDataSet.Tables("HQ_BADGE").(i)("HQBD_PASSWORD").tostring() + "','" + objDataSet.Tables("HQ_BADGE").(i)("HQBD_MFGNO").tostring() + ")"
'Next
'DataAdapter.Fill(ds, "Badge")
'for each ( datarow rowExcel in ds.Tables("T_HQ_BADGE"))
' rowExcel.SetAdded() ' sets its RowState to "Added"
' DataSet.Tables("import1").ImportRow(rowExcel)
'Next
End Sub
Protected Function ExcelConnection() As OleDbCommand
Dim xConnStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= C:\Import from Excel\Badge.xls ;Extended Properties=""Excel 12.0;HDR=Yes;IMEX=2""" 'Connection String to Excel Workbook
' create your excel connection object using the connection string
Dim objXConn As New OleDbConnection(xConnStr)
'objXConn.Open()
Dim Command As New OleDbCommand("SELECT [HQBD_PLAZANO],[HQBD_BADGENO],[HQBD_GROUPLEVEL],[HQBD_BADGENAME],[HQBD_PASSWORD],[HQBD_MFGNO] FROM [Badge$]", objXConn)
Return Command
End Function
End Class
Hai,
here i wrote my code.can any one plz suggest me how to bind the dataset data to oracle database temporary table.
main thing is no need to show in gridview.that data just insert in the temporary table.
plz any one suggest me.
Thaks in advance.