reading xml from database..

P

prashant

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........
 
A

Alexey Smirnov

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);
}
 
A

Alexey Smirnov

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())
 
S

Steven Cheng[MSFT]

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.
 
Top