Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Access SQLXML Technology from .NET Apps : Page 3

The SQLXML Managed Classes enable developers to access SQLXML technology from .NET applications. This article describes some of these classes and how to use them.


advertisement
Use Templates
When you use SQLXML, you can place your XPath, XQuery, or SQL statements in templates. Templates also are XML documents that encapsulate database queries. You could say that templates separate your database queries from your program code. When you include hard-coded queries in your programs, templates make the process of maintaining those programs easier--you dont have to change the program code when you change a query.

The following listing shows how to use templates:

using System; using System.IO; using System.Data; using Microsoft.Data.SqlXML; public class TemplateSample { public static void Main() { String strConnectionString = Provider=SQLOLEDB;Server=(local); database=Northwind;user id=sa;pwd=; Stream stream; SqlXMLCommand cmd = new SqlXMLCommand(strConnectionString); cmd.CommandStream = new FileStream(Template.XML, FileMode.Open, FileAccess.Read); cmd.CommandType = SqlXMLCommandType.Template; stream = cmd.ExecuteStream(); StreamReader reader = new StreamReader(stream); Console.Writeline(reader.ReadToEnd()); Console.ReadLine(); } }



The contents of the template file Template.XML is shown in the following lines:

<ROOT XMLns:sql=urn:schemas-microsoft-com:XML-sql> <sql:query> SELECT * FROM Customers WHERE CustomerID=ALFKI FOR XML AUTO </sql:query> </ROOT>



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap