|
| ||
|
| ||
|
Personal Tech | |
|
| ||
|
|
How to Use SQLXML to Retrieve Data from SQL Server Database?
Using SQL Server 2000 and above versions you can retrieve data from SQL Server in XML format directly from the database. Many XML related features were incorporated in the SQL Server database. This enables the development of XML enabled applications very easy and it makes exchange of data over internet easy. In this article we will discuss about how to use SQLXML to retrieve data directly from SQL server database in XML format. There are some SQL commands and clauses that help you to retrieve data from the SQL Server in the XML format. Syntax for such is given below: SELECT ... FOR XML mode [, XMLDATA] [, ELEMENTS] [, BINARY BASE64] There are different modes and that take the values of · AUTO - In this mode every row of the result of the query forms an element in the returned XML document. · EXPLICIT - This mode defines how to map the columns of the results returned by the query to the XML elements and the attributes. · RAW - All the fields of the result are identified as attributes of an element. · NESTED - The result of this mode is the same as the AUTO mode but the formatting has to be done at the client side. A simple example of using the above syntax is given below: SELECT TOP 3 * FROM (SELECT FirstName+' '+LastName as Name FROM Employees) FOR XML AUTO The query produces this result: Employees Name="John Peter" There are optional parameters in the 'FOR XML mode' clause. The XMLDATA option adds an XSD schema which describes the XML format of the result returned. The ELEMENTS options make the fields of the tables in the database to be returned as child elements. If the ELEMENTS option is not there the fields of the tables are returned as attributes instead of child elements of the XML document. The ELEMENTS option is allowed only in the AUTO mode. The BINARY BASE64 option is used to retrieve any binary data. The returned binary data is returned in BASE64 encoded format. The binary data can be retrieved in the RAW or EXPLICIT mode. An example of the RAW mode is given below: SELECT EmpName, EmpCity from EMP for XML RAW The above code returns a result like, row EmpName="John" EmpCity="New York" In the above result you can note that the fields of the resultset are returned as attributes of the element. .Net provides with managed classes for interacting with SQL Server. The managed classes of SQLXML provided by .Net are: · SqlXmlCommand - This is used to perform queries that are stored in XML documents which are also called XML templates. This class also provides support for client side XML processing. · SqlXmlParameter - this is used to provide parameterized values and is used along with SqlXmlCommand object. · SqlXmlAdapter - this is the adapter class for SQLXML provider. This is used to fill the dataset. · SqlXmlException - this is used to trap the error information from the SQL Server. A sample code using the managed classes is given below. For detailed information on the usage of the above managed classes you can refer to the MSDN documentation. static string cstr = "Provider=SQLOLEDB;Server=(local);database=EmpPersonal;"; public static void testingSqlXml () { Stream oStr = Console.OpenStandardOutput(); SqlXmlCommand sqlcmd = new SqlXmlCommand(cstr); sqlcmd.Root = "Employees"; sqlcmd.CommandType = SqlXmlCommandType.Sql; sqlcmd.CommandText = "SELECT EmpName, EmpCity FROM Employees FOR XML AUTO"; strm = sqlcmd.ExecuteToStream(oStr); oStr.Close(); } Thus we have seen that SQLXML can be used to retrieve data directly from the SQL Server in XML format. It is easy to handle and transmit data through the internet if it is in the XML format and this can be easily achieved using the SQLXML. Want to stay current with the latest technology developments realted to XML. Visit Free XML Tutorial to get your FREE subscription now! ** Attention Webmasters / Website Owners ** You can reprint this article on your website as long as you do not modify any of the content, and include our resource box as listed above with all links intact and hyperlinked properly.
MORE RESOURCES: |
RELATED ARTICLES
Portable DVD Players - Things To Know In my humble opinion nothing makes a long trip easier (especially if you have kids). A portable DVD player is the ideal solution for those long plane rides or endless drives in a car to keep everyone entertained, especially when you have new hit DVD to play. Dynamite Comes in Small Packages - Tiny Personal Audio MP3 Players Pack Powerful Music Enjoyment MP3 players are Hot! Playing music has come a long way since the transistor radio, portable tape and CD player days. Most players are no larger than a deck of cards. Be Your Own IT Department If you use a computer, you need to know more than just how to use your email and surf the web. You need to know that you are protected. Your Computer Cant Keep Time A computer needs a certain amount of information to operate; for example, the date and time, the amount of memory installed, the number of drives and their configuration, and so on. In the early days of computers, either the user typed in this information each time the computer started, or it was set using DIP switches and jumpers. Things You Can Do To Speed Up Your Computer Upgrading your processor will always speed up your computer, but sometimes this will not be the best thing to do. The first thing you need to do is find out where the bottle neck is in your system. More Cool Web Tricks If you ask most people what frustrates them most about the Internet, many of them will tell you "It's the little things!"It seems like all the great tricks and tips that make people exclaim "STOP! How did you do that?" never make it into any manual (at least where I can find them).My father (and co-author of "Turn Words Into Traffic") calls it the "reverse oral tradition" of computing, where children teach parents the survival skills of PC life. 4 Computer Money-saving Tips Tip #1 -- Rebates: A rebate is not always a bargain. Computers with rebates are often close to being discontinued. Classification of Computers Computers are available in different shapes, sizes and weights, due to these different shapes and sizes they perform different sorts of jobs from one another.They can also be classified in different ways. Desktop Security Software Risks - Part 2 This is the third in a series of articles highlighting reasons why we need a new model for anti-virus and security solutions.Reason #2: the Desktop Security Software RisksThe risks of placing software on the desktop are such that I will be breaking this article into two parts. Occupational Therapy and PDAs Occupational Therapy Made EasierMedical downloads for the pda have improved the life of both patients and doctors of all kinds. These freeware software downloads make many types of medical conditions much easier to manage. Computer Viruses are Bad Luck OK, so you caught a computer virus and your system is all screwed up and you're frustrated and angry and upset. Bad luck. Cisco Certification: Taking Your First Certification Exam Youâ??ve studied hard; youâ??ve practiced your configurations; youâ??ve used your flash cards over and over again; and finally, the big day is here. Your first certification exam!For many Cisco certification candidates, their first exam is the CCNA Composite exam or one of the two exams that make up the CCNA, the Introduction To Networking exam or the ICND (Interconnecting Cisco Networking Devices) exam. Your Home is in Your Hands I would like to tell you about a magic home. You or your children have bought a home and fixed it up very nicely. Are You Well Protected? Winter?the official start of the cold and flu season. Though, technically speaking, things got started a little early. JVCs First Three-Layer Combo-Disc Blu-Ray / DVD JVC developed and used a high-performance reflective film to produce this revolutionary three layer structure. The outer Blu-ray layer can be read by the blue light laser but it is transparent for the red light laser which therefore has access to the inner dual DVD layer. Cisco Certification: Building Your Home Lab, Part II In the first part of this home lab tutorial, CCNA and CCNP candidates can see that there are a LOT of choices when it comes to what to buy to build your own Cisco practice lab.Having been there myself, I know itâ??s confusing to decide how many routers or switches to buy, and what I need at the minimum to run labs and get some great hands-on practice. Image Formats: GIF, JPEG, BMP When browsing the internet you are likely to come across many different image formats. However, the most common formats are: CompuServe GIF, JPEG, and Bitmaps. Help, I Need a New HDTV! (Part 4 of 5) Feeling overwhelmed in selecting a new TV? With all the choices these days, you may feel like, "Where do I start?!"In part 4 of our 5 part article, we the discuss "do I really need an HDTV?"---Right now, stations are moving towards HDTV programming. Although available for free over the air in major metropolitan areas, this process will take a few years to fully unfold. Wordpress Plugins Maybe you always wanted a feature that hasn't been available in the latest release of Wordpress. What you can do is either install a 3rd party plugin or write your own custom code to extend the features of Wordpress. Help, I Need a New HDTV! (Part 3 of 5) Feeling overwhelmed in selecting a new TV? With all the choices these days, you may feel like, "Where do I start?!"In part 3 of our 5 part article, we the discuss what HDTV is.HDTV stands for High Definition TV. |
|
Personal Tech | Site Map | VirRex | Map | Web Domain Directory | Greeting | Directory | Photo Gallery Card | Newey | View Card | Free Calendar |
| © 2006 - 2009 |