开发者

Use DBF database with .Net Winform application

As I am working on windows .Net Windows form application, I want to know that can we use开发者_运维百科 DBF (a FoxPro OR Dbase database file) in .Net Windows form application ?

I want to use DBF as the back-end database for my winform .Net application.

Please let me know if you have any ideas/solution on it.

Thanks in advance.


According to connectionstrings.com, there are several ways to connect to a DBF.

Simply use the correct connection string, and you should be fine.


Use ODBC class to access DBF files. Look at connectionstrings.com to find out the right connection string. It should be the following:

string dbfDirectory = @"C:\the_path_to_my_dbf_file_or_files";

using (OdbcConnection conn = new OdbcConnection(@"Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=" + dbfDirectory + ";"))
{
    conn.Open();

    using (OdbcCommand cmd = conn.CreateCommand())
    {
        cmd.CommandText = "SELECT * FROM myDbFileFromTheUpperDirectory.dbf";

        using (OdbcDataReader reader = cmd.ExecuteReader())
        {
            while (reader.Read())
            {
                // do something
            }
        }
    }
}


If you have an OLE DB (preferred) or ODBC driver for it, then yes, absolutely.


Additionally to the above, since .DBF files are also associated with Visual FoxPro applications, you can easily hook up with VFP's OleDB provider instead of ODBC.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜