有以下代码:
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;
}
}
我需要获取条目数,但我得到例外:
解析查询时出错
我不明白我犯了什么错误。请描述一个问题。
答案 0 :(得分:0)
可能是正确的括号“)”:
string sql = string.Format("SELECT COUNT(*) FROM {0})"