473,394 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

reading xml from database..

Hi all,
i am working with .net 2.0 and sql server managment studio of
version--9.00.1399.00

for getting a xmldocument from a xml data in sqlserver ..

their is no error in this program but xmlreader returned by
line-->
"XmlReader xmlUser = xmlMain.CreateReader();

shows that xmlUser.HasValue is false but the "xmlMain" has the Xml
document...and the end result i am getting is null in XmlDocumnet named
userdoc....and thats not our requirment

the function is following:--

public static XmlDocument GetXmlDocument(string coloumName,
SqlDataReader sqlReader)
{
int ordinal = sqlReader.GetOrdinal(coloumName);
XmlDocument userDoc = new XmlDocument();
if (ordinal 0)
{
SqlXml xmlMain = sqlReader.GetSqlXml(ordinal);

if (!xmlMain.IsNull)
{
XmlReader xmlUser = xmlMain.CreateReader();
if (xmlUser.HasValue)
{
userDoc.Load(xmlUser);
}
}
return userDoc;
Thanx in advance........
Mar 24 '07 #1
4 1281
On Mar 24, 12:13 pm, prashant <efex...@newsgroups.nospamwrote:
Hi all,
i am working with .net 2.0 and sql server managment studio of
version--9.00.1399.00

for getting a xmldocument from a xml data in sqlserver ..

their is no error in this program but xmlreader returned by
line-->
"XmlReader xmlUser = xmlMain.CreateReader();

shows that xmlUser.HasValue is false but the "xmlMain" has the Xml
document...and the end result i am getting is null in XmlDocumnet named
userdoc....and thats not our requirment

the function is following:--

public static XmlDocument GetXmlDocument(string coloumName,
SqlDataReader sqlReader)
{
int ordinal = sqlReader.GetOrdinal(coloumName);
XmlDocument userDoc = new XmlDocument();
if (ordinal 0)
{
SqlXml xmlMain = sqlReader.GetSqlXml(ordinal);

if (!xmlMain.IsNull)
{
XmlReader xmlUser = xmlMain.CreateReader();
if (xmlUser.HasValue)
{
userDoc.Load(xmlUser);
}
}
return userDoc;

Thanx in advance........
HasValue returns a true if the node on which the reader is currently
positioned has a value. You suppose you wanted to read the first node

XmlReader xmlUser = xmlMain.CreateReader();
if (xmlUser.Read)
{
userDoc.Load(xmlUser);
}

Mar 24 '07 #2
On Mar 24, 10:29 pm, "Alexey Smirnov" <alexey.smir...@gmail.com>
wrote:
HasValue returns a true if the node on which the reader is currently
positioned has a value. You suppose you wanted to read the first node

XmlReader xmlUser = xmlMain.CreateReader();
if (xmlUser.Read)
{
userDoc.Load(xmlUser);
must be if (xmlUser.Read())

Mar 24 '07 #3
Hi

As Alexey has suggested, after you create the XmlReader from SqlXml
instance, you can call its "Read()" method to read into the underlying XML
stream. Also, you need to first call "Read" method on the SqlDataReader you
get so as to move to the first returned record:

e.g.

================
using (SqlCommand command =
connection.CreateCommand())
{
command.CommandType = CommandType.Text;
command.CommandText = sql;
command.Parameters.AddRange(sqlParams);

connection.Open();

using (SqlDataReader dr =
command.ExecuteReader())
{
if (dr.Read())
document.Load(
dr.GetSqlXml(0).CreateReader());
}

connection.Close();
}

===========================

Here are some web articles discussing on this:

#XML Data Type Support in ADO.NET 2.0: Handling XML from SQL Server 2005
http://msdn2.microsoft.com/en-us/library/ms971534.aspx

#XML Data type in ADO.Net v2.0 - Part II
http://blogs.msdn.com/sushilc/rss_ta...taType+w_2F00_
ADO.Net+2.0.xml

#Work with XML Data Type in SQL Server 2005 from ADO.NET 2.0
http://www.developer.com/net/net/art...1087_3406251_3

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.



Mar 26 '07 #4
Hi prashant,

How are you doing on this issue, have you got any progress? If there is
still anything we can help, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 28 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dariusz | last post by:
I have PHP code (below) which reads data from a MySQL format database. The problem I am having is trying to find out when the last ID entry was made. When the script is executed, the $gbID is...
1
by: Google Mike | last post by:
Tell me if this can be done, and if I have a misconception here. I am writing an app that will be served up in an app farm, and therefore I need to move the session information to the client, not...
2
by: Dariusz | last post by:
Below is part of a code I have for a database. While the database table is created correctly (if it doesn't exist), and data is input correctly into the database when executed, I have a problem...
0
by: Andy | last post by:
Hi, In the code below (not pretty I know but it's an early version :-P) I'm having problems reading the data object back in. If I move the reading code to immediately after the section where it...
7
by: John Pote | last post by:
Hello, help/advice appreciated. Background: I am writing some web scripts in python to receive small amounts of data from remote sensors and store the data in a file. 50 to 100 bytes every 5 or...
2
by: Ed | last post by:
Hope someone can help me out... I have been tasked to read some image data from an sql database and save the files to flat files. OK, sounds easy as I'v used BLOBs before. But this is an old...
7
by: ianenis.tiryaki | last post by:
well i got this assignment which i dont even have a clue what i am supposed to do. it is about reading me data from the file and load them into a parallel array here is the question: Step (1) ...
0
by: Andrea | last post by:
Hi, I've a problem reading a field containing a crypted string. I read the field via JDBC but when I decrypt the string I obtain a sequence of strange characters (if I output them I obtain a...
2
by: Derik | last post by:
I've got a XML file I read using a file_get_contents and turn into a simpleXML node every time index.php loads. I suspect this is causing a noticeable lag in my page-execution time. (Or the...
1
by: =?Utf-8?B?QWRyaWFuTW9ycmlz?= | last post by:
Hello All, I am trying to read an Excel spreadsheet (xls) programmatically. I have used the ODBC database route and have opened the Excel spreadsheet and then using a 'CRecordset', I read each...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.