简体   繁体   中英

Insert with Entity Framework with SQL Compact 3.5

I dont know why my sql request does not insert on database.

I think the db.Create(pers) does works.

private void SaveInsertAnim(object sender, EventArgs e)
{
    using (var db = new DJURINGA_DIRECTOREntities())
    {
        PERSONNE pers = new PERSONNE();


        pers.NOM = textBox1.Text;
        pers.PRENOM = textBox2.Text;
        pers.ADRESSE = textBox9.Text;
        pers.CODEPORTE = textBox3.Text;
        pers.EMAIL = textBox4.Text;
        pers.TELEPHONE = textBox5.Text;
        pers.NUMSECU = textBox6.Text;
        pers.DATENAISSANCE = Convert.ToDateTime(dateTimePicker2.Text); 
        pers.LIEUNAISSANCE = textBox8.Text;
        pers.DATEDEBUTSEJOUR = Convert.ToDateTime(dateTimePicker1.Text);
        if(!string.IsNullOrWhiteSpace(comboBox2.Text)) pers.NOMBRESEMAINETRAVAILLE = int.Parse(comboBox2.Text);
        pers.REDUCTIONSNCF = textBox10.Text;
        if (!string.IsNullOrWhiteSpace(comboBox1.Text)) pers.NOMBREJOURPRECAMP = int.Parse(comboBox1.Text);


         db.Create(pers);
         db.SaveChanges();


        this.Hide();
    }
}

My Functions Create() :

public static T Create(this ObjectContext context, T objetToCreate, bool save = false) where T : EntityObject { try { var type = context.GetSetBase(typeof(T));

            if (context.GetKeyName<T>().Count == 1)
            {
                context.SetValeurToKey(objetToCreate);
            }

            context.AddObject(type.Name, objetToCreate);
            if (save) context.SaveChanges();
            return objetToCreate;
        }
        catch (Exception ex)
        { throw ex; }
    }

Do you have any ideas ?

i have no error, but nothing works ..

Look for a copy of the database file in your bin/debug folder. Possible solutions: specify a full path to the database file in your connectionstring. Do not include the database file a content in your project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM