0

大家好,我有一个小应用程序来增加一天的费用。

为此,我使用 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 结构如下:

在此处输入图像描述

我能够从同一数据库的另一个表中检索数据。会有什么问题?

4

1 回答 1

1

每当我收到有关不存在的表的错误时,我都会使用 SQL Server Management Studio 并检查该表是否真的丢失,或者我的查询中是否有拼写错误。

不幸的是,当前版本的 Management Studio 不再支持 SQL Server Compact 数据库,您将不得不使用 2008 版本。您可以直接从 Microsoft 获得:SQL Server 2008 R2 Management Studio Express

于 2014-01-02T12:16:54.300 回答