首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用OleDbDataAdapter从句使用系统错误

用OleDbDataAdapter从句使用系统错误
EN

Stack Overflow用户
提问于 2016-10-11 11:18:56
回答 1查看 90关注 0票数 0

使用adapter可以很好地工作,但是当我使用adapter2时,我会得到一个错误。

注意:代码是用于form1的。我使用两个组框和两个数据视图。

代码语言:javascript
复制
   `private OleDbConnection connection = new OleDbConnection();
    DataTable table = new DataTable();
    OleDbDataAdapter adapter = new OleDbDataAdapter();
    DataSet set = new DataSet();

    public Home()
    {
        InitializeComponent();
        connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\DatabesSystem.accdb;Persist Security Info=False;";
        adapter1();
        adapter2();
    }

    private void adapter1()
    {
        try
        {
            OleDbDataAdapter adapter = new OleDbDataAdapter("select CID, Firstname, Middlename, Lastname, Address, Contact_Number, Email from Clients", connection);
            adapter.Fill(set, "Clients");
            table = set.Tables["Clients"];
            dataGridView1.DataSource = table;
        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

    private void adapter2()
    {
        try
        {
            OleDbDataAdapter adapter2 = new OleDbDataAdapter("select Transaction_Number, Client_Name, Unit_Name, Full_Price, Down_Payment, Monthly_Payment, Remaning_Balance from Transaction", connection);
            adapter2.Fill(set, "Transaction");
            table = set.Tables["Transaction"];
            dataGridView2.DataSource = table;
        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }`
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-11 11:40:49

Transaction是SQL中的保留关键字。尝试将表名写在括号中:

代码语言:javascript
复制
OleDbDataAdapter adapter2 = new OleDbDataAdapter("select Transaction_Number, Client_Name, Unit_Name, Full_Price, Down_Payment, Monthly_Payment, Remaning_Balance from [Transaction]", connection);

或者在另一个表中重命名您的表名。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39976068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档