Hi fellow members of Daniweb.

I've been working on project for the past few days now, and have come across a bump, that i am unable to pass.
The project, when finished, will do the following:

  1. Select DBF file from computer location (Default C:)
  2. Import the database file into a DataGridView
  3. Export the Datagridview into a file type of choice (For the meantime it will be an .XSLX file)

Now i know there are many software out there that do this already, however i require this one for unique capabilities within my workplace.

Currently, i can open a OpenFileDialog, select the file i need, and import it. However the Datagridview stays empty. and i recieve no error.

Im very interested to see why/how this happens - and hoping somebody can point out where i have gone wrong.

The following code executes when the file has been chosen and the user hits 'btnNext':

    If txtFileName.Text = "" Then
         MsgBox("Error! You must choose a file!")
         Return
    End If
    dbfiledir = ofdFileSearch.FileName.ToString()
    dbfilename = ofdFileSearch.SafeFileName.ToString().Split(".")(0)
    dbfilefolder = dbfiledir.Substring(0, 3)
    Me.Hide()
    MsgBox(dbfilefolder) 'The 3 messagebox's are a part of my testing.
    MsgBox(dbfilename)
    MsgBox(dbfiledir)
    frmStepTwo.visible = True

Now when frmStepTwo appears the following gets executed:

    Dim cnn As New System.Data.OleDb.OleDbConnection
    Dim da As New System.Data.OleDb.OleDbDataAdapter
    Dim theDataSet As New DataSet

    cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfilefolder & ";Extended Properties=dBASE IV;User ID=Admin;Password=;"
    Try
        cnn.Open()
        da.SelectCommand = New System.Data.OleDb.OleDbCommand("select * from [" & dbfilename & "]", cnn)
        da.Fill(theDataSet)
        DataGridView1.DataSource = theDataSet
        DataGridView1.Refresh()
    Catch ex As Exception
        MsgBox("Error while connecting to databse." & vbNewLine & ex.Message & vbNewLine & ex.ToString)
    End Try

This is all well and good, however no results in the database. I did some research to see if it had anything to do with the connectionstring. And i beleive this is the correct statement.

Any help with this issue, is greatly appreciated.

Regards

Here is an example that you can follow to read in the DBASE file. It is slightly different than the method you are using.

   Dim ofd As New OpenFileDialog
   With ofd
      .Filter = "DBASE File (*.dbf)|*.dbf"
      .Multiselect = False
      .CheckFileExists = True
   End With

   If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
      Dim fi As New IO.FileInfo(ofd.FileName)

      Dim cn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=dBase IV;Data Source='" _
                                          & fi.DirectoryName & "'")
      Dim TableName As String = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length)
      Dim cmd As New OleDb.OleDbCommand(TableName, cn)
      cmd.CommandType = CommandType.TableDirect
      Dim dt As New DataTable
      cn.Open()
      Dim rdr As OleDb.OleDbDataReader = cmd.ExecuteReader
      dt.Load(rdr)
      DataGridView1.DataSource = dt
      cn.Close()
      cn.Dispose()
   End If
Comments
This solution has fixed my issue!

Here is an example that you can follow to read in the DBASE file. It is slightly different than the method you are using.

Excellent! Thanks heaps, this works a charm! So much relief!

I know this post have been solved, but I have a doubt!

How can i Split the results with a delimiter in the datagridview?

for example if I have many columns (columnames)like: AlexSmithCoronado

how I get the results in the datagridview from the dbf like: Name col col
Alex Smith Coronado

thanks in advanced.

This question has already been answered. Start a new discussion instead.