Why can't I insert data into a local database (SQL Compact Edition) using C #?

I am doing a project in Visual Studio. I am using a local database (empty sql server compact version). I selected Dataset and created a table (Images). It has a primary auto-increment identifier column and an nvarchar ImagePath image column. I want to insert data into it, and here is my code.

SqlCeConnection con = new SqlCeConnection();
con.ConnectionString = yeniApplicationDatabase.Properties.Settings.Default.DatabaseEdaConnectionString;
con.Open();
using (SqlCeCommand com = new SqlCeCommand("INSERT INTO Images (ImagePath) VALUES ('book')", con))
{
  com.ExecuteNonQuery();
}

I don't know why, but this one does not give any error, syntax (SQL) is fine. However, when I check the table data, it is still zero. That's what:

In the same run ,
I execute this code, then I execute another that selects * from the images ...
It shows a "book". But still, the table data is empty, and when I re-run it without insertion, only selecting from the images, it disappeared again. I really don't understand what is going on. Why can't I put anything in my database?

I also added con.Close (), but it still does not work.

+3
source share
3 answers
SqlCeConnection con = new SqlCeConnection();
con.ConnectionString =  yeniApplicationDatabase.Properties.Settings.Default.DatabaseEdaConnectionString;
con.Open();
SqlCeCommand com = new SqlCeCommand("INSERT INTO Images (ImagePath) VALUES ('book')", con);

com.ExecuteNonQuery();


com.Dispose();
con.Close();

Closing the connection should complete the insertion.

EDIT: update solution

(.sdf) , , . .sdf bin\Debug. , , bin\Debug.

: SQL Compact 3.5?, , . .

+8

Eclipse, -, Visual Studio , - Copy file .

"", , bin\debug , - . , , .

, IDE . " "? ? ?

+2
SqlCeConnection conn = new SqlCeConnection(@"Data Source = c:\FullPath") 

How to get the full path: in Solution Explorer Right-click on .Sdf, then get fullPath.

0
source

All Articles