Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

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.



Thanks for your registration, follow us on our social networks to keep up-to-date