有人知道如何使用C#从oledb驱动程序删除pack foxpro数据 [英] someone knows how to delete pack foxpro data from oledb driver with c#

查看:80
本文介绍了有人知道如何使用C#从oledb驱动程序删除pack foxpro数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

//Probando insercion
        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();
        }

我在foxpro 9中有一个数据库,其中有一个名为test的测试表,并且我使用了正常的sql语句进行了测试,一切正常,除了pack语句从数据库中物理删除了数据外,我发现了一个示例,该示例向我展示了如何做到这一点,但它可以与其他驱动器(adodb)一起使用,但是即使我可以使用该代码来完成它,我也想知道这些东西在oledb中如何工作.

i have a database in foxpro 9 with one testing table named test, and i tested with normal sql sentences, and everything is going fine except for the pack statement whom delete data physically from the database, i found and example that shows me how to do it but its with other kinda drive (adodb), but even if i can do it with that code i want to know how could this stuff works in oledb.

推荐答案

    static void Main(string[] args)
    {
    Console.WriteLine("Starting program execution...");

    string connectionString = @"Provider=VFPOLEDB.1;Data Source=h:\dave\"; 

    using (OleDbConnection connection = new OleDbConnection(connectionString)) 
    { 
        using (OleDbCommand scriptCommand = connection.CreateCommand()) 
        { 
            connection.Open();

            string vfpScript = @"SET EXCLUSIVE ON
                                DELETE FROM test WHERE id = 5
                                PACK"; 

            scriptCommand.CommandType = CommandType.StoredProcedure; 
            scriptCommand.CommandText = "ExecScript"; 
            scriptCommand.Parameters.Add("myScript", OleDbType.Char).Value = vfpScript; 
            scriptCommand.ExecuteNonQuery(); 
        } 
    } 

    Console.WriteLine("End program execution..."); 
    Console.WriteLine("Press any key to continue"); 
    Console.ReadLine(); 
    }

这篇关于有人知道如何使用C#从oledb驱动程序删除pack foxpro数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆