Ground series of six new data wpf_MVVM_006

New data:
(1): Examples of the physical model Entitys
(2): Examples of the need to add the table, assigned legal values
(3): Save the data;
example:
(1): = new new myEntities myEntities, myModel ();
(2):
the Table1 myTable the Table1 new new = ();
. myTable assignment field a = a;
myTable two field assignment = II;.

myModel.Table1.Add(myTable);
(3):
if( myModel.SaveChanges() > 0 )
	MessageBox.Show("新增成功");
else  
	MessageBox.Show("新增失败");

Notes: [1]: if, else statement functions in only one code can omit the braces "{}";
[2]: save the code may be a write only: myModel.SaveChanges ();
[3]: Assignment when the need to verify the data type and length, are often needed .trim () after removal of the space length verification.
Not exceed the length of the data length field in the database, the data type is not differentiated, otherwise an exception is thrown.
[4]: Available try {} catch (Exception ex) to catch the error.

Published 130 original articles · won praise 36 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_44548307/article/details/104756130