.NET
  Home arrow .NET arrow Page 4 - Introducing LINQ with XML and Databases
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Introducing LINQ with XML and Databases
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2008-06-16

    Table of Contents:
  • Introducing LINQ with XML and Databases
  • Querying the Database
  • LINQ to XML
  • XML Literals in Visual Basic

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Introducing LINQ with XML and Databases - XML Literals in Visual Basic


    (Page 4 of 4 )

    There's one final thing I'd like to mention on the topic of LINQ to XML. If you're using Visual Basic, you can drop literal XML right into your code:


    Dim document As XDocument = _

     <?xml version="1.0" encoding="utf-8" standalone="yes"?>

     <people>

     <person>

     <name>Bob</name>

     <age>35</age>

     </person>

     <person>

     <name>Henry</name>

     <age>43</age>

     </person>

     <person>

     <name>Joe</name>

     <age>22</age>

     </person>

     <person>

     <name>Chuck</name>

     <age>29</age>

     </person>

     </people>


    In order to recreate the last example, you would simply wrap the query in <%= %> tags:


    Dim overThirtyDocument As XDocument = _

     <?xml version="1.0" encoding="utf-8" standalone="yes"?>

     <people>

     <%= From p In document.Descendants("person") _

     Where CInt(p.Element("age")) > 30 _

     Select p %>

     </people>


    Conclusion

    LINQ is a powerful new tool in the .NET developer's toolbox. It integrates data access directly into .NET languages, providing a very readable query language that can be used on a variety of data sources. In these two articles, we covered objects, XML files and databases, but LINQ supports other data sources, too, that you may want to look into.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hello, all,This is a continuation of my...
     

    .NET ARTICLES

    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek