查看: 808|回复: 1
|
connection string的一个小疑问
[复制链接]
|
|
ConnectionString: "provider=Microsoft.Jet.OLEDB.4.0; data source='C:\Documents and Settings\Administrator\My Documents\NAME LIST 1G.xls '; Extended Properties=Excel 8.0;"
以上的connectionString 可以让我fetch data from Excel file.. 那么如果我要fetch data from csv file该如何修改呢?
我进去ODBC data source administrator有看到 microsoft text driver is support (*.txt) & (*.csv), 但就是不懂该如何修改我现有的coding...
the following is my complete source code for fetch data from excel file and display to datagrid...
Public Function ImportAttendence(ByVal PrmPathExcelFile As String, ByVal DataGrid1 As DataGrid)
Dim MyConnection As System.Data.OleDb.OleDbConnection
Try
' Fetch Data from Excel
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source='" & PrmPathExcelFile & " '; " & "Extended Properties=Excel 8.0;")
' Select the data from Sheet1 of the workbook.
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [sheet1$]", MyConnection)
MyCommand.TableMappings.Add("Table", "Attendence")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
DataGrid1.DataSource = DtSet.Tables(0)
MyConnection.Close()
Catch ex As Exception
MyConnection.Close()
End Try
End Function
[ 本帖最后由 counterking 于 31-5-2006 03:52 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 31-5-2006 09:39 PM
|
显示全部楼层
|
|
|
|
|
|
| |
本周最热论坛帖子
|