locked
How to save data to Db using SQLce and EI RRS feed

  • Question

  • I have created a =n EI Model and can query it just fine, but need help with saving new and updated data to the Db.

    Can someone point me to something that describes how this is done with SQLce since there are no store procedures with SQLce?


    Tom Childers, Radio Amateur N5GE, Licensed since 1976, QCWA Member 35102, ARRL Life Member
    Saturday, January 28, 2012 9:10 PM

Answers

  • > So, you are saying that to insert data into a database that is modeled would be something like this? [...] SQL = "insert data into table...."
       
      
    please take a close look at the following examples.
    (there is no sql, just code, which creates database, inserts and updates data)
      
      
    Saturday, January 28, 2012 10:33 PM

All replies

  • > need help with saving new and updated data to the Db.


    an examples are here (SaveChanges and SubmitChanges)
      
      
    Saturday, January 28, 2012 9:28 PM
  • > need help with saving new and updated data to the Db.


    an examples are here (SaveChanges and SubmitChanges)
      
      

    Thank you for the reply, but I was asking about SQL Server Compact Edition 4.0, not SQL Express..

    Do you know how to save changes to CE 4.0 when using an Entity Model?

    Thanks,

     


    Tom Childers, Radio Amateur N5GE, Licensed since 1976, QCWA Member 35102, ARRL Life Member
    Saturday, January 28, 2012 9:50 PM
  • > I was asking about SQL Server Compact Edition 4.0, not SQL Express.. Do you know how to save changes to CE 4.0 when using an Entity Model?


    an approach is the same. just use SqlCeConnection.

    using System.Data.Common;
    using System.Data.Entity;
    using System.Data.Linq;
    using System.Data.SqlServerCe;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication3
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                var d1 = new Data1(new SqlCeConnection(@"Data Source=C:\Temp\Test.sdf"));
                var d2 = new Data2(new SqlCeConnection(@"Data Source=C:\Temp\Test.sdf"));
            }
        }
    
        public class Data1 : DataContext
        {
            public Data1(DbConnection dc) : base(dc) { }
            // ...
        }
    
        public class Data2 : DbContext
        {
            public Data2(DbConnection dc) : base(dc, true) { }
            // ...
        }
    }
    
    
     
     

    Saturday, January 28, 2012 10:00 PM
  • > I was asking about SQL Server Compact Edition 4.0, not SQL Express.. Do you know how to save changes to CE 4.0 when using an Entity Model?


    an approach is the same. just use SqlCeConnection.

    using System.Data.Common;
    using System.Data.Entity;
    using System.Data.Linq;
    using System.Data.SqlServerCe;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication3
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                var d1 = new Data1(new SqlCeConnection(@"Data Source=C:\Temp\Test.sdf"));
                var d2 = new Data2(new SqlCeConnection(@"Data Source=C:\Temp\Test.sdf"));
            }
        }
    
        public class Data1 : DataContext
        {
            public Data1(DbConnection dc) : base(dc) { }
            // ...
        }
    
        public class Data2 : DbContext
        {
            public Data2(DbConnection dc) : base(dc, true) { }
            // ...
        }
    }
    
    
     
     


    So, you are saying that to insert data into a database that is modeled would be something like this?

     public class Data2 : DbContext
        {
            public void Data2(DbConnection dc) : base(dc, true) 
    {
    // preparation code....
    SQL = "insert data into table...."
    // execution code ....
     } }
    Is that correct?

    Tom Childers, Radio Amateur N5GE, Licensed since 1976, QCWA Member 35102, ARRL Life Member
    Saturday, January 28, 2012 10:16 PM
  • > So, you are saying that to insert data into a database that is modeled would be something like this? [...] SQL = "insert data into table...."
       
      
    please take a close look at the following examples.
    (there is no sql, just code, which creates database, inserts and updates data)
      
      
    Saturday, January 28, 2012 10:33 PM