更新表(行)Access 2007和C#2010

时间:2012-09-10 18:12:17

标签: c# database ms-access-2007

所以这可能是最天真的问题,但这就是我猜的问题; 然后,我的问题是我不知道如何将Visual C#Express 2010连接到Access 2007并在C#中的应用程序中进行典型的插入,更新,删除和搜索,我刚刚学习了基础知识(完成了一个控制台教程,我相信它比以前更有用,以前使用访问97的VB6背景,我一直在这里和网上搜索,但我唯一能找到的msdn教程我找不到的地方。<登记/> 因此,在我的应用程序中,我只需要链接组合框,查询这些值以获取新的值,进行计算然后存储在数组中(也许可以在数据网格中显示它们以及从所述数据网格中编辑它们,我猜这有点复杂)并最终将它们存储在各种表格中,但我还没有真正找到一本强大的(或者很可能是简单的)手册,它将指导我使用winforms创建典型的应用程序插入,更新和删除。 为了做到这一点,你们有什么好的联系吗?

感谢。

1 个答案:

答案 0 :(得分:0)

您可以尝试使用此代码

此处有关字符串连接的链接:http://www.connectionstrings.com/access-2007

var query = "...";
var connectionString = "...";

    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        // The insertSQL string contains a SQL statement that
        // inserts a new row in the source table.
        using(var command = new OleDbCommand(query))
        {    
        // Set the Connection to the new OleDbConnection.
        command.Connection = connection;

        // Open the connection and execute the insert command.
        try
        {
            connection.Open();
            command.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        // The connection is automatically closed when the
        // code exits the using block.
        }
    }