none
VB2003如何將資料(*.txt,*.csv)匯入DataTable內 RRS feed

  • 問題

  • 如何將資料(*.txt,*.csv)匯入DataTable內

    我有將控制台-->資料來源(ODBC)-->使用者資料來源名稱-->新增Microsoft Text Driver

            Dim conn As OdbcConnection
            Dim com As OdbcCommand
            Dim Da As OdbcDataAdapter
            Dim Dset As New DataSet
            Dim Dr As OdbcDataReader
            Dim DStr, SelectStr, Ofile As String
            If OpenFileDialog1.ShowDialog = DialogResult.OK Then
                Dim sr As New StreamReader(OpenFileDialog1.FileName)
                sr.Close()
            End If
            TextBox2.Text = OpenFileDialog1.FileName
            Ofile = OpenFileDialog1.FileName
            DStr = "Driver={Microsoft Text Driver (*.txt; *.csv)};dbq=" & Ofile & ""
            SelectStr = "select * from " & Ofile & ""
            conn = New OdbcConnection(DStr)
            Try
                Da = New OdbcDataAdapter(SelectStr, conn)
                Da.Fill(Dset, "Data")
                DataGridView1.DataSource = Dset.Tables("Data")
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try

    但是程式還是出現錯誤

    所以想要請教各位專業~

    2008年6月30日 上午 06:38

所有回覆