大家好,我有一个小应用程序来增加一天的费用。
为此,我使用 SQL 紧凑型数据库 (CE)。将记录插入表名费用时,我收到错误
指定的表不存在。[花费]
插入代码是
using (var con =new SqlCeConnection(@"Data Source=|DataDirectory|\Database\Acadamy.sdf;
Persist Security Info=False"))
{
con.Open();
try
{
var Cmd = new SqlCeCommand();
String sqlAddNew = @"INSERT INTO Expenses (name, amount,receipt,details)
Values(@name,@amount,@receipt,@details)";
Cmd = new SqlCeCommand(sqlAddNew, con);
Cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = txtName.Text;
Cmd.Parameters.Add("@amount", SqlDbType.NVarChar).Value = txtAmount.Text;
Cmd.Parameters.AddWithValue("@receipt", SqlDbType.NVarChar).Value = txtRecept.Text;
Cmd.Parameters.AddWithValue("@details", SqlDbType.NVarChar).Value = txtDetails.Text;
Cmd.ExecuteNonQuery();
}
catch (Exception exception)
{
txtAmount.Text = exception.ToString();
}
finally
{
if (con.State == ConnectionState.Open) con.Close();
}
}
}
我不明白为什么会发生此错误。Acadamy.sdf 结构如下:
我能够从同一数据库的另一个表中检索数据。会有什么问题?