0

我有这个代码:

public void FillData()
    {
        // 1 step. Open connection
        string conection = @"Data Source=|DataDirectory|db.sdf;Persist Security Info=False;";
        try
        {
            SqlCeConnection c = new SqlCeConnection(conection);
            c.Open();

            // 2 step. Create new DataAdapter
            using (SqlCeDataAdapter a = new SqlCeDataAdapter("SELECT * FROM USER", c))
            {
                // 3 step. Use DataAdapter to fill table
                DataTable t = new DataTable();
                a.Fill(t);
                // 4 step. Render data on the DataGridView
                dataGridViewUsers.DataSource = t;
            }
        }
        catch (SqlException e)
        {
            MessageBox.Show(e.Message);
        }

    }

我可以连接到数据库,但SqlCeDataAdapter启动此错误:

There was an error parsing the query. [Token line number = 1, Token line offset = 15, Token in error = USER]

我的数据库有一个名为 的表USER,那么这段代码有什么问题?

4

1 回答 1

2

USER 是保留字。[USER]像在查询中一样传递它。您的查询应该是这样的。

new SqlCeDataAdapter("SELECT * FROM [USER]", c))
于 2013-01-11T11:04:30.733 回答