<p>I have searched for various techniques on how to read/write dBase III (dbf) files using OLEDB or ODBC with C#/.NET.  I have tried almost all of the tecniques posted, but without success.  Can someone point me in the right direction?</p>

<p>Thanks for your time.</p>

[{'answer_id': 75846, 'author': 'Kearns', 'author_id': 6500, 'author_profile': 'https://Stackoverflow.com/users/6500', 'pm_score': 2, 'selected': False, 'text': '<p>FoxPro 2.0 files were exactly the same as dBase III files with an extra bit for any field that was of type "memo" (not sure the exact name, it\'s been a while). That means that if you just use a <a href="http://www.connectionstrings.com/?carrier=visualfoxpro" rel="nofollow noreferrer">FoxPro 2.x method</a> for accessing the files, it should work.</p>\n'}, {'answer_id': 75915, 'author': 'Fionnuala', 'author_id': 2548, 'author_profile': 'https://Stackoverflow.com/users/2548', 'pm_score': 3, 'selected': False, 'text': '<p>Something like ... ?</p>\n\n<pre><code> ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" &amp; _\n"Data Source=e:\\My Documents\\dBase;Extended Properties=dBase III"\nDim dBaseConnection As New System.Data.OleDb.OleDbConnection(ConnectionString )\ndBaseConnection.Open()\n</code></pre>\n\n<p>From: <a href="http://bytes.com/forum/thread112085.html" rel="noreferrer">http://bytes.com/forum/thread112085.html</a></p>\n'}, {'answer_id': 779865, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>This is a nice aproach, i didn\'t tested, but i will soon...</p>\n\n<p><a href="http://www.c-sharpcorner.com/uploadfile/rfederico/xbaseenginerfv12022005011623am/xbaseenginerfv.aspx" rel="nofollow noreferrer">http://www.c-sharpcorner.com/uploadfile/rfederico/xbaseenginerfv12022005011623am/xbaseenginerfv.aspx</a></p>\n'}, {'answer_id': 10492908, 'author': 'Dejan Janjušević', 'author_id': 828023, 'author_profile': 'https://Stackoverflow.com/users/828023', 'pm_score': 3, 'selected': False, 'text': '<p>I realize this is an old thread, but in case someone gets here by google (like I have few days ago).. As I wrote <a href="https://stackoverflow.com/questions/3206029/optimal-way-to-handle-dbf-from-c-sharp/10492849#10492849">here</a>, the elegant solution is to use <a href="http://linqtovfp.codeplex.com/" rel="nofollow noreferrer">LINQ to VFP</a> to read from and write to DBF files. I tested it with some dBase III files. It goes like this:</p>\n\n<p>You define your table to match the DBF definition like this:</p>\n\n<pre><code>public partial class MyTable \n{\n    public System.Int32 ID { get; set; }\n    public System.Decimal Field1 { get; set; }\n    public System.String Field2 { get; set; }\n    public System.String Field3 { get; set; }\n}\n</code></pre>\n\n<p>You define the context like this:</p>\n\n<pre><code>public partial class Context : DbEntityContextBase \n{\n    public Context(string connectionString)\n        : this(connectionString, typeof(ContextAttributes).FullName) \n    {\n    }\n\n    public Context(string connectionString, string mappingId)\n        : this(VfpQueryProvider.Create(connectionString, mappingId)) \n    {\n    }\n\n    public Context(VfpQueryProvider provider)\n        : base(provider) \n    {\n    }\n\n    public virtual IEntityTable&lt;MyTable&gt; MyTables \n    {\n        get { return this.GetTable&lt;MyTable&gt;(); }\n    }\n}\n</code></pre>\n\n<p>You define context attributes like this:</p>\n\n<pre><code>public partial class ContextAttributes : Context \n{\n    public ContextAttributes(string connectionString)\n        : base(connectionString) {\n    }\n\n    [Table(Name="mytable")]\n    [Column(Member="ID", IsPrimaryKey=true)]\n    [Column(Member="Field1")]\n    [Column(Member="Field2")]\n    [Column(Member="Field3")]\n    public override IEntityTable&lt;MyTable&gt; MyTables \n    {\n        get { return base.MyTables; }\n    }\n}\n</code></pre>\n\n<p>You also need a connection string, you can define it in app.config like this (<code>Data\\</code> relative path is used as the source of DBF files in this case):</p>\n\n<pre><code>&lt;connectionStrings&gt;\n  &lt;add name="VfpData" providerName="System.Data.OleDb"\n    connectionString="Provider=VFPOLEDB.1;Data Source=Data\\;"/&gt;\n&lt;/connectionStrings&gt;\n</code></pre>\n\n<p>And finally, you can perform reading and writing to and from DBF files as simple as:</p>\n\n<pre><code>// Construct a new context\nvar context = new Context(ConfigurationManager.ConnectionStrings["VfpData"].ConnectionString);\n\n// Write to MyTable.dbf\nvar my = new MyTable\n{\n    ID = 1,\n    Field1 = 10,\n    Field2 = "foo",\n    Field3 = "bar"\n}\ncontext.MyTables.Insert(my);\n\n// Read from MyTable.dbf\nConsole.WriteLine("Count:  " + context.MyTables.Count());\nforeach (var o in context.MyTables)\n{\n    Console.WriteLine(o.Field2 + " " + o.Field3);\n}\n</code></pre>\n'}, {'answer_id': 36814803, 'author': 'DRapp', 'author_id': 74195, 'author_profile': 'https://Stackoverflow.com/users/74195', 'pm_score': 0, 'selected': False, 'text': '<p>I have offered many answers on working with database files (more specifically VFP, but the Microsoft VFP OleDb provider will recognize older dbase files.  You can do a search to find more of these links via:</p>\n\n<p>user:74195[vfp][oledb]</p>\n\n<p>First, I would start with getting the <a href="https://www.microsoft.com/en-us/download/details.aspx?id=14839" rel="nofollow noreferrer">Microsoft VFP OleDb Provider</a> download.</p>\n\n<p>Next, if you already have some dbf files you are trying to connect to for testing, you need to establish a connection.  The connection must point to the PATH where the files are located, not the specific .dbf file.  So, if you have a folder with 20 tables in it, once you connect to the PATH, you can query from any/all the tables via standard VFP-SQL Syntax (common with many sql the overall structure, but different based on some functions like string, date and number manipulations).</p>\n\n<p>Learn about PARAMETERIZING your queries.  With VFP OleDb, parameters are done with the "?" character as a place-holder, so the parameters need to be added in the exact same sequence as they appear in the query.  The "?" can appear as field values, join conditions, where criteria, etc.</p>\n\n<p>The following are a FEW to get you started to HOPEFULLY get you started with a valid connection, query, then insert/update/delete with parameters.</p>\n\n<ol>\n<li><p><a href="https://stackoverflow.com/questions/33746435/how-to-query-a-foxpro-dbf-file-with-ndx-index-file-using-the-oledb-driver-in-c/33746532#33746532">Sample showing a connection string and simple query from a table</a></p></li>\n<li><p><a href="https://stackoverflow.com/questions/32578233/create-dbf-file-from-sql-table-records/32696552#32696552">Shows a parameterized sql-insert</a>but in this case gets the data from another data source, such as sql-server and creating a VFP/dbf style table from it.  It goes through cycling through records and pulling values for each parameter and inserting.</p></li>\n<li><p><a href="https://stackoverflow.com/questions/30648602/oledb-update-command-not-changing-data/30650636#30650636">and another showing parameterized SQL-update</a></p></li>\n</ol>\n\n<p>Good luck, and there are plenty of others who answer on VFP and OleDb Access, these are just some that I have specifically participated in and show functional implementations that may have something you may otherwise may have missed.</p>\n'}]
['https://Stackoverflow.com/questions/75705', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10333/']