0

Here is the way i create a DBF file = ANSI file :

var path = @"Z:\";
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path +   ";Extended Properties=dBASE IV;User ID=Admin;Password=;";
OleDbConnection con = new OleDbConnection(constr);
con.Open();

string CreateTableK =
   "CREATE TABLE TEST (ID char(50),NAME char(50),FAMILY char(50))";

OleDbCommand cmdCreateTable = new OleDbCommand(CreateTableK, con);
cmdCreateTable.ExecuteNonQuery();

string MyInsert =
   "insert into TEST ( ID, NAME, FAMILY ) values ( ?, ?, ? )";
OleDbCommand cmd3 = new OleDbCommand(MyInsert, con);
cmd3.Parameters.AddWithValue("parmSlot1", "22");
cmd3.Parameters.AddWithValue("parmSlot2", "Oliver");
cmd3.Parameters.AddWithValue("parmSlot3", "¢ُںُ");

cmd3.ExecuteNonQuery();

MessageBox.Show("done");

i removed all using... for clarify what am i saying.
Now open TEST.DBF file in Drive Z:\ and see how parmSlot3 has changed.
I want to have "¢ُںُ" string with no change in DBF file.
How can i define encoding of DBF file or How can i do this job?


Also in the other hand i want to read that string from DBF file and work with that string.
Here is the codes :
        var path = @"Z:\";
        var fileName = "TEST.DBF";
        string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=dBASE IV;";
        using (OleDbConnection con = new OleDbConnection(constr))
        {
            var sql = "select * from " + fileName;
            OleDbCommand cmd = new OleDbCommand(sql, con);
            con.Open();

            OleDbDataReader reader = cmd.ExecuteReader();

            string value = "";

            if (!reader.HasRows)
            {
                 //BLO BLO BLO 
            }
            else
            {
                while (reader.Read())
                {
                    value = reader.GetString(2);
                    break;
                }
            }
        }

but after these codes value is different from "¢ُںُ" string.
How can i get "¢ُںُ" string instead of "تُاُ"?

Zero Piraeus
  • 56,143
  • 27
  • 150
  • 160
SilverLight
  • 19,668
  • 65
  • 192
  • 300
  • my problem after the comment : that answer uses Provider=VFPOLEDB.1 in connection string and i am using visual studio 2012 with .net 4.5. why i have error about this driver? should i use that instead of Microsoft.Jet.OLEDB.4.0? – SilverLight Dec 01 '14 at 21:43
  • so this is not duplicate, please don't vote to close and let me get my answer here. appreciate it. – SilverLight Dec 01 '14 at 21:44
  • it says possible duplicate.. anyway you need to check the Culture or Encoding of the DB Environment – MethodMan Dec 01 '14 at 21:45
  • please show me some codes... i checked that answer and the error is : The 'VFPOLEDB.1' provider is not registered on the local machine – SilverLight Dec 01 '14 at 21:56
  • sounds like you need to make sure that the dll and or OLEDB Provider is installed on that machine.. – MethodMan Dec 01 '14 at 21:58
  • here is the link for fix that error : http://stackoverflow.com/questions/15684575/getting-the-error-the-vfpoledb-1-provider-is-not-registered-on-the-local-mach but where should i change that platfrom in vs 2012? – SilverLight Dec 01 '14 at 22:00
  • i think here is the solution : http://stackoverflow.com/questions/17621949/how-can-i-change-the-build-platform-property-in-a-visual-studio-project – SilverLight Dec 01 '14 at 22:09
  • that's good that you are thinking :) so what have you tried based on that supposed solution ? – MethodMan Dec 01 '14 at 22:13
  • I can't tell you what to do or not to do it's really hard to advice someone when we can't see nor do we know your environment.. also why do you have double `;` here in this line `Extended Properties=dBASE IV;;` have you looked at [ConnectionString](http://www.connectionstrings.com) it's a great site for how to format a connection for DBASE, SQL Server, SqlLite, etc... – MethodMan Dec 01 '14 at 22:37
  • is this what you are expecting "¢???" please specify your language ok – MethodMan Dec 01 '14 at 22:51
  • dear admin, please close this thread. links in comments were very useful. that answer is my answer and my problem solved. but if there is an other way would be happy to know that. – SilverLight Dec 02 '14 at 00:34

0 Answers0