把Excel文件中的数据读入到DataGrid中
Private Function CreateDataSource()
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Book1.xls;Extended Properties=Excel 8.0;"
Dim conn As New OleDbConnection(strConn)
Dim myCommand As New OleDbDataAdapter("select * from [Sheet1$]", strConn)
Dim myDataSet As New DataSet
myCommand.Fill(myDataSet)
Return myDataSet
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.DataGrid1.DataSource = CreateDataSource()
Me.DataGrid1.DataBind()
End Sub
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Book1.xls;Extended Properties=Excel 8.0;"
Dim conn As New OleDbConnection(strConn)
Dim myCommand As New OleDbDataAdapter("select * from [Sheet1$]", strConn)
Dim myDataSet As New DataSet
myCommand.Fill(myDataSet)
Return myDataSet
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.DataGrid1.DataSource = CreateDataSource()
Me.DataGrid1.DataBind()
End Sub