Load(@"C:\Wrox\Linq\Chapter5\Contacts.xml");
foreach (XElement xelem in xel.Elements("Contact"))
{
Contact con = new Contact();
con.NameStyle = 1;
con.Title = (string)xelem.Element("Title");
con.FirstName = (string)xelem.Element("FirstName");
con.MiddleName = (string)xelem.Element("MiddleName");
con.LastName = (string)xelem.Element("LastName");
con.EmailAddress = (string)xelem.Element("EmailAddress");
con.EmailPromotion = (int)xelem.Element("EmailPromotion");
con.PasswordHash = (string)con.Element("PasswordHash");
con.PassswordSalt = (string)con.Element("PasswordSalt");
db.Contact.Add(con);
db.SubmitChanges();
}
lable1.Visible = true;
Run the project and click the XML to SQL button. When the insertion is successful, the label on the form
displays the text ??????Insert successful.??™??™ To verify the results, open a new query window in SSMS (SQL
Server Management Studio). Select the AdventureWorks database and execute the following query:
SELECT ContactID, NameStyle, Title, FirstName, MiddleName, LastName,
EmailAddress, EmailPromotion, PasswordHash, PasswordSalt
FROM Person.
Pages:
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263