如何从Compact Edition SQL中获取所选条目的数量?

时间:2012-09-29 19:06:03

标签: c# sql-server-ce

有以下代码:

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;
    }
}

我需要获取条目数,但我得到例外:

  

解析查询时出错

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

1 个答案:

答案 0 :(得分:0)

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

string sql = string.Format("SELECT COUNT(*) FROM {0})"