Sub BindData()
Dim OpenFile As String
Dim i As Integer
OpenFile = "MyXls/Sheet1.xls"
'*** Create Excel.Application ***'
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet1 As Excel.Worksheet
xlBook = xlApp.Workbooks.Open(Server.MapPath(OpenFile))
xlBook.Application.Visible = False
xlSheet1 = CType(xlBook.Worksheets(1), Excel.Worksheet)
'*** Create DataTable ***'
Dim dt As New System.Data.DataTable
Dim dr As System.Data.DataRow
'*** Column ***'
dt.Columns.Add("id")
dt.Columns.Add("name")
dt.Columns.Add("lname")
For i = 0 To 2
'*** Rows ***'
dr = dt.NewRow
dr("id") = xlSheet1.Cells.Item(i, 0).Value
dr("name") = xlSheet1.Cells.Item(i, 1).Value
dr("lname") = xlSheet1.Cells.Item(i, 2).Value
dt.Rows.Add(dr)
Next
'*** End DataTable ***'
'*** BindData To DataGrid ***'
Me.myRepeater.DataSource = dt
Me.myRepeater.DataBind()
'*** Quit and Clear Object ***'
xlApp.Application.Quit()
xlApp.Quit()
xlSheet1 = Nothing
xlBook = Nothing
xlApp = Nothing
End Sub
Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
Dim strConnString As String
Dim strSQL As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database/EVALUATION.mdb") & ";"
objConn = New OleDbConnection(strConnString)
objConn.Open()
Dim chkID As System.Web.UI.WebControls.CheckBox
Dim lblID, lblName, lbllname As System.Web.UI.WebControls.Label
Dim i As Integer
For i = 0 To myRepeater.Items.Count - 1
chkID = CType(myRepeater.Items(i).FindControl("chkID"), CheckBox)
lblID = CType(myRepeater.Items(i).FindControl("lblid"), Label)
lblName = CType(myRepeater.Items(i).FindControl("lblname"), Label)
lbllname = CType(myRepeater.Items(i).FindControl("lbllname"), Label)
If chkID.Checked = True Then
'*** Insert Record ***'
strSQL = "INSERT INTO Table1 (id,name,lname) " & _
" VALUES ('" & lblID.Text & "','" & lblName.Text & "','" & lbllname.Text & "') "
objCmd = New OleDbCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
End If
Next
Me.pnlForm.Visible = False
Me.lblText.Text = "Record Inserted."
objConn.Close()
objConn = Nothing
End Sub