在网上找了一下原本是C#的.........我改成VB但是出错.......
[CODE] Dim oleDbConnection As New OleDbConnection
Dim myConnection As New OleDbConnection
Dim datatable As DataTable
Dim datatable1 As DataTable
Dim query, connExcel, connAccess As String
Dim dataset As New DataSet
Dim oleAdapter As New OleDbDataAdapter
Dim sqlDA1 As New OleDbDataAdapter
Dim sqlCB1 As New OleDbCommandBuilder
connExcel = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("book1.xls") + ";Extended Properties=Excel 8.0"
oleDbConnection = New OleDbConnection(connExcel)
oleDbConnection.Open()
datatable = OleDbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Null)
query = "SELECT * FROM [Sheet1$]"
dataset = New DataSet
oleAdapter = New OleDbDataAdapter(query, connExcel)
oleAdapter.Fill(dataset)
' DataGrid1.DataSource = dataset.Tables(0).DefaultView
' DataGrid1.DataBind()
connAccess = "provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("data\data.mdb")
myConnection = New OleDbConnection(connAccess)
Try
myConnection.Open()
sqlDA1 = New OleDbDataAdapter(@"SELECT * FROM 题目表", myConnection)
datatable1 = New DataTable
sqlCB1 = New OleDbCommandBuilder(sqlDA1)
sqlDA1.Fill(datatable1)
Dim datarow1 As DataRow
datarow1 = Null
Dim DataRow As DataRow
For Each DataRow In dataset.Tables(0).Rows
datarow1 = datatable1.NewRow()
datarow1("编号") = DataRow("编号")
datarow1("类型") = DataRow("类型")
datatable1.Rows.Add(datarow1)
Next
Response.Write("新插入 " + datatable1.Rows.Count.ToString() + " 条记录")
sqlDA1.Update(datatable1)
Catch
Response.Write("出错!!!")
End Try
myConnection.Close()
oleDbConnection.Close()
End Sub[/CODE]
各位帮我看看!!!!!!!!!!!!!!!!!谢谢!!!!!