質問

Hi all I have an small application to add the expense of the day.

For this I am using SQL compact database (CE). While inserting the record into a table name Expenses I am getting error

The specified table does not exist. [Expenses]

Insertion code is

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

I am not getting why this error occurring. Acadamy.sdf structure is as below:

enter image description here

I am able to retrieve data from another table of the same database. What will be the problem?

役に立ちましたか?

解決

Whenever I get an error about a table that does not exist I use the SQL Server Management Studio and check if the table really is missing or if I just have a typo in my query.

Unfortunately the current version of the Management Studio no longer supports SQL Server Compact Database and you will have to use the 2008 version. You can get it directly from Microsoft: SQL Server 2008 R2 Management Studio Express

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top