I have a single DBF file
which I can open using Microsoft Visual FoxPro
and I now need to add through Visual Studio 2012
in C#
lnauage data to it.
I'm getting this error: Invalid authorization specification.
with this code:
DialogResult result = MessageBox.Show("Do you wish to submit?", "Potvrzení", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
odcCON.Open();
OleDbCommand odc = new OleDbCommand("INSERT INTO netpokl.DBF (Castka,Akce) values(@castka,@akce)");
odc.Parameters.AddWithValue("@castka",textBox2.Text);
odc.Parameters.AddWithValue("@akce",test);
odc.ExecuteNonQuery();
odcCON.Close();
}
OleDbConnection is this:
OleDbConnection odcCON = new OleDbConnection(" Provider=SQLOLEDB;Data Source=\\SERVER\\Transfer\netpokl.DBF");
To read/write dbase files you can use the Microsoft JET OLEDB provider, with a connection string that looks like this one:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\directory;Extended Properties=dBASE IV;User ID=Admin;Password=
Note that Data Source is the folder where your dbase file is. Finally in your query the table name should be the file name without the .dbf extension, like this:
INSERT INTO netpokl (Castka,Akce) values(@castka,@akce)
Should you need this to work on a 64bit application you can use the Microsoft ACE OLEDB provider (Microsoft Access Database Engine 2010 Redistributable)
Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=dBASE IV;Data Source=c:\directory;