飞鱼的BLOG

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::
'==采用ODBC方式读取CSV文件
        'Dim strConn As String = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" & lstrFileFolder '   //filePath, For example: C:\"
        'strConn += ";Extensions=asc,csv,tab,txt;HDR=Yes;FMT=Delimited;"
        'Dim objConn As OdbcConnection = New OdbcConnection(strConn)
        'Dim dsCSV As New DataSet
        'Try
        '   Dim strSql As String = "select * from " & newfilename                    'fileName, For example: 1.csv
        '   Dim odbcCSVDataAdapter As New OdbcDataAdapter(strSql, objConn)
        '   odbcCSVDataAdapter.Fill(dsCSV)
        'Catch ex As Exception
        'End Try


        
'''采用OLEDB方式直接读取CSV文件
        'Dim FilePath As String = lstrFileFolder
        'Dim conn1 As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FilePath & ";Extended Properties=""text;""")

        
'Dim command1 As New OleDbCommand("", conn1)
        'Dim dataadapter1 As New OleDbDataAdapter(command1)
        'Dim dt_data As New DataTable
        'command1.CommandText = "SELECT * FROM " & lstrFileName
        'dataadapter1.Fill(dt_data)


        
'''=======采用IO.StreamReader直接读取CSV
        ''Dim intColCount As Integer = 0
        ''Dim blnFlag As Boolean = True
        ''Dim mydt As New DataTable

        
''Dim mydc As DataColumn
        ''Dim mydr As DataRow

        
''Dim strpath As String = lstrFileNamePath
        ''Dim strline As String
        ''Dim aryline() As String

        
''Dim i As Integer
        ''Dim rowNum As Integer

        
''Dim mysr As System.IO.StreamReader = New System.IO.StreamReader(strpath, System.Text.Encoding.GetEncoding("GB2312"))
        '''        dim aa as String = mysr.ReadBlock
        ''strline = mysr.ReadLine()
        ''rowNum = 1
        ''While (strline <> Nothing)
        ''    aryline = Split(strline, ",")
        ''    If rowNum = 1 Then
        ''        If (blnFlag = True) Then
        ''            blnFlag = False
        ''            intColCount = aryline.Length
        ''            For i = 0 To aryline.Length - 1
        ''                mydc = New DataColumn(aryline(i))
        ''                mydt.Columns.Add(mydc)
        ''            Next
        ''        End If
        ''    Else
        ''        mydr = mydt.NewRow()
        ''        For i = 0 To intColCount - 1
        ''            mydr(i) = aryline(i)
        ''        Next
        ''        mydt.Rows.Add(mydr)
        ''    End If
        ''    strline = mysr.ReadLine()
        ''    rowNum = rowNum + 1
        ''End While
posted on 2006-02-13 19:51  飞在空中的鱼  阅读(955)  评论(0)    收藏  举报