0

有以下代码:

private void FormViewing_Load(object sender, EventArgs e)
{
    OpenConnection();
    FillFields();
}

private void OpenConnection()
{
    connectionString = string.Format("DataSource=\"{0}\"; Password=\"{1}\"", dbPath, Constants.DB_PASSWORD);
    connection = new SqlCeConnection(connectionString);
    connection.Open();
}

private void FillFields()
{
    string sql = string.Format("SELECT COUNT(*) FROM {0})", 
        Constants.TABLE_NAME);
    SqlCeCommand selectCommand = new SqlCeCommand(sql, connection);
    try
    {
        Console.WriteLine(selectCommand.ExecuteScalar());
    }
    catch (Exception exeption)
    {
        this.Text = exeption.Message;
    }
}

我需要计算条目数,但出现异常:

解析查询时出错

我不明白我犯了什么错误。请描述一个问题。

4

1 回答 1

0

它可能是正确的括号“)”在:

string sql = string.Format("SELECT COUNT(*) FROM {0})"
于 2012-09-29T19:08:49.217 回答