[英]Insert with Entity Framework with SQL Compact 3.5
I dont know why my sql request does not insert on database. 我不知道为什么我的sql请求没有插入数据库。
I think the db.Create(pers) does works. 我认为db.Create(pers)确实有效。
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() : 我的函数Create():
public static T Create(this ObjectContext context, T objetToCreate, bool save = false) where T : EntityObject { try { var type = context.GetSetBase(typeof(T)); 公共静态T创建(此ObjectContext上下文,T objetToCreate,布尔保存=假),其中T:EntityObject {试试{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. 在bin / debug文件夹中查找数据库文件的副本。 Possible solutions: specify a full path to the database file in your connectionstring.
可能的解决方案:在连接字符串中指定数据库文件的完整路径。 Do not include the database file a content in your project
不要在项目中包含数据库文件的内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.