Unable to insert data into local database in WPF

In the project, I have a local database (I use datagrid to view the data), but the problem is that when pasting into the database using the insert request, the insert is not long, i.e. when I restart the application, the database does not change and the changes are not reflected in the database view (lookup table data in Visual Studio).

Request for input:

string dbCon = new     System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\MyDatabase.sdf";
        SqlCeConnection dbconnection = new SqlCeConnection("datasource=" + dbCon);

        dbconnection.Open();

        String Insert = "insert into MainTable(LineID,Date,Connection_Type)  Values('5','5/8/2012','commercial')";
SqlCeCommand cmd = new SqlCeCommand(Insert, dbconnection);

        //// Execute the command
        cmd.ExecuteNonQuery();

        dbconnection.Close();

Now that this code is working, the datagrid is updated, but the changes are not permanent. What am I doing wrong? I am using Visual Studio 2010 Ultimate and Windows 7

+3
source share
2 answers

? , , sdf ( Windows 7, UAC ).

, sdf, , AppData, , , guaruntee , .

0
  • Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\MyDatabase.sdf" - . . "DataSource=|DataDirectory|\\MyDatabase.sdf;...", .

  • , , . , , . . , ; , .

  • Visual Studio , , , , Copy to Output Directory "Copy". , , , , , , . , . . .

0

All Articles