this is my code
OleDbConnection conexionFoxPro = new OleDbConnection();
string rutaFoxPro = @"C:\Users\BigMander\Documents\Proyectos de Visual FoxPro\prueba.dbc";
conexionFoxPro.ConnectionString = String.Format("Provider=VFPOLEDB.1;Data Source={0};Exclusive=Yes;", rutaFoxPro);
bool sePudoEjecutarTodo = true;
try
{
conexionFoxPro.Open();
OleDbCommand comandoFoxPro = new OleDbCommand();
comandoFoxPro.CommandText =
@"INSERT INTO test ([nombre], [telefono], [id]) VALUES (?, ?, ?)";
comandoFoxPro.Parameters.Add("nombre", OleDbType.Char).Value = "bigmander";
comandoFoxPro.Parameters.Add("telefono", OleDbType.Char).Value = "some number";
comandoFoxPro.Parameters.Add("id", OleDbType.Integer).Value = 5;
comandoFoxPro.Connection = conexionFoxPro;
sePudoEjecutarTodo &= (comandoFoxPro.ExecuteNonQuery() > 0);
comandoFoxPro.CommandText =
@"SELECT nombre, telefono FROM test";
OleDbDataReader reader = comandoFoxPro.ExecuteReader();
while (reader.Read())
{
Console.WriteLine("{0}: {1}", reader.GetName(0), reader["nombre"]);
Console.WriteLine("{0}: {1}", reader.GetName(1), reader["telefono"]);
}
reader.Close();
reader.Dispose();
comandoFoxPro.CommandText =
"DELETE FROM test WHERE id = 5";
sePudoEjecutarTodo &= (comandoFoxPro.ExecuteNonQuery() > 0);
comandoFoxPro.CommandText =
"SET EXCLUSIVE ON; PACK test";
sePudoEjecutarTodo &= (comandoFoxPro.ExecuteNonQuery() > 0);
}
catch(OleDbException oleDbE)
{
sePudoEjecutarTodo = false;
Console.WriteLine(oleDbE.Message);
}
finally
{
if (sePudoEjecutarTodo)
Console.WriteLine("Congratulaciones si se armo todo");
else
Console.WriteLine("Pelas");
conexionFoxPro.Close();
Console.ReadKey();
}
I have a database in foxpro 9 with one test table called test, and I tested it with the usual sql clauses, and everything is going fine, except for the package operator, which physically removes the data from the database, I found an example that shows me how to do it, but with a different kind of disk (adodb), but even if I can do it with this code, I want to know how this stuff can work in oledb.
source
share