none
Connect and Read data from DBF RRS feed

  • Question

  • Hi,

    I would like to ask how can I connect to DBF and read data from it? I tried below code but nothing is happenning and I am not getting the MessageBox shown!

    string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Temp\ReemData\Database\NewData;Extended Properties=dBASE IV;";
    
    sql_connection = new OleDbConnection(connectionString);
    
    sql_connection.Open();
    
    MessageBox.Show("Connected");
    
    OleDbCommand cmd = new OleDbCommand("SELECT * FROM gndsale", sql_connection);
    
    MessageBox.Show("SELECTED");
    

    Kindly help..

    Thanks,

    Jassim

    Wednesday, September 21, 2016 10:19 PM

Answers

  • Hi Jassim Rahma,

    For your project, it is a windows from application. I do some change.

    Please try the following. I tried it. It works.

    In designer.

    Here is the code.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.OleDb;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace read_data_from_DBF3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string connectionString = @"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\\Users\\wendy\\Desktop; Extended Properties = DBASE IV;";
                OleDbConnection sql_connection = new OleDbConnection(connectionString);
                sql_connection.Open();
                MessageBox.Show("Connected");
                OleDbCommand cmd = new OleDbCommand("Select * from gndsale.dbf", sql_connection);
                MessageBox.Show("SELECTED");
            }
        }
    }

    Here is the output.

    I hope this would be helpful to you.

    If it solves your problem, please mark as answer.

    If you have something else, please feel free to contact us.

    Best Regards,

    Wendy


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, September 23, 2016 1:37 AM
    Moderator
  • Hi Jassim Rahma,

    Thank  you for feedback.

    >>The 'Microsoft.Jet.OLEDB.4.0'provider is notregistered on the localmachine.

    1.What is the system type of your PC? 32 bits or 64 bits?

    Try to change the platform target.  Right click the project>properties>Build

    My computer is 64 bits and it works well.

    2.What is the version of SQL server?

    The Microsoft OLE DB Provider for Jet provides an OLE DB interface to Microsoft Access databases, and allows SQL Server 2005 and later distributed queries to query Access databases and Excel spreadsheets.

    For your question, you could upgrade the version to the latest。

    3.Maybe you could try the Microsoft.ACE.OLEDB.12.0.

    string connectionString = @"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\\Users\\wendy\\Desktop; Extended Properties = DBASE IV;";

    For the use of Microsoft.ACE.OLEDB.12.0, it would be better to install Microsoft Access Database Engine 2010 Redistributable.

    I hope this would be helpful to you.

    If you have something else, please feel free to contact us.

    Best Regards,

    Wendy


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 26, 2016 5:31 AM
    Moderator

All replies

  • Hi Jassim Rahma,

    Thank you for posting here.

    For your question, I tested your code.

    Please try the code below. I tried it. It works.

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.OleDb;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace read_data_from_DBF
    {
        class Program
        {
            static void Main(string[] args)
            {
                string connectionString = @"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\\Users\\wendy\\Desktop; Extended Properties = DBASE IV;";
                OleDbConnection sql_connection = new OleDbConnection(connectionString);
                sql_connection.Open();
                MessageBox.Show("Connected");
                OleDbCommand cmd = new OleDbCommand("SELECT * FROM testdbf.dbf", sql_connection);
                MessageBox.Show("SELECTED");
            }
        }
    }

    I hope this would be helpful to you.

    If you have something else, please feel free to contact us.

    Wendy


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, September 22, 2016 6:42 AM
    Moderator
  • Hi,

    Thanks for your reply

    I am still having the same problem.

    here is the project with the DBF included

    http://www.jassimrahma.com/temp/connect_to_dbf.rar

    Thursday, September 22, 2016 6:41 PM
  • Hi Jassim Rahma,

    For your project, it is a windows from application. I do some change.

    Please try the following. I tried it. It works.

    In designer.

    Here is the code.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.OleDb;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace read_data_from_DBF3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string connectionString = @"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\\Users\\wendy\\Desktop; Extended Properties = DBASE IV;";
                OleDbConnection sql_connection = new OleDbConnection(connectionString);
                sql_connection.Open();
                MessageBox.Show("Connected");
                OleDbCommand cmd = new OleDbCommand("Select * from gndsale.dbf", sql_connection);
                MessageBox.Show("SELECTED");
            }
        }
    }

    Here is the output.

    I hope this would be helpful to you.

    If it solves your problem, please mark as answer.

    If you have something else, please feel free to contact us.

    Best Regards,

    Wendy


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, September 23, 2016 1:37 AM
    Moderator
  • Hi Wendy,

    It's still the same

    I am not getting the message nor errors

    this is the updated code:

    string connectionString = @"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\\Temp\\ReemData\\Database\\NewData; Extended Properties = DBASE IV;";
    OleDbConnection sql_connection = new OleDbConnection(connectionString);
    sql_connection.Open();
    MessageBox.Show("Connected");
    OleDbCommand cmd = new OleDbCommand("Select * from gndsale.dbf", sql_connection);
    MessageBox.Show("SELECTED");
    

    Sunday, September 25, 2016 11:23 AM
  • I moved the code from Load to ButtonClick and I am getting:

    The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.

    Sunday, September 25, 2016 1:15 PM
  • Hi Jassim Rahma,

    Thank  you for feedback.

    >>The 'Microsoft.Jet.OLEDB.4.0'provider is notregistered on the localmachine.

    1.What is the system type of your PC? 32 bits or 64 bits?

    Try to change the platform target.  Right click the project>properties>Build

    My computer is 64 bits and it works well.

    2.What is the version of SQL server?

    The Microsoft OLE DB Provider for Jet provides an OLE DB interface to Microsoft Access databases, and allows SQL Server 2005 and later distributed queries to query Access databases and Excel spreadsheets.

    For your question, you could upgrade the version to the latest。

    3.Maybe you could try the Microsoft.ACE.OLEDB.12.0.

    string connectionString = @"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\\Users\\wendy\\Desktop; Extended Properties = DBASE IV;";

    For the use of Microsoft.ACE.OLEDB.12.0, it would be better to install Microsoft Access Database Engine 2010 Redistributable.

    I hope this would be helpful to you.

    If you have something else, please feel free to contact us.

    Best Regards,

    Wendy


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 26, 2016 5:31 AM
    Moderator