473,386 Members | 1,785 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,386 software developers and data experts.

Xml Problem , Please Help

Hi ,

I have a stored procedure which return an xml by using the (for xml
auto/explicit) which working fine under the Query Analyzer .

and i would like to build simple function that get the sp name and execute
it and return the xml result .

what is the best way to do that ?

Best Regards ,

Tiraman :-)
Nov 12 '05 #1
6 2057
Hi Tiraman,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get the Xml results from a
SQL stored procedure. If there is any misunderstanding, please feel free to
let me know.

I think we can get the Xml data from the database and fill them to a
DataSet. Then, we join all the strings in the table to form a complete xml
document. We can use an XmlTextReader to read it. Here is a code snippet
for your reference.

this.sqlConnection1.Open();
SqlDataAdapter sda = new SqlDataAdapter("GetEmployeeXml",
this.sqlConnection1);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
sda.Fill(ds);
string s = string.Empty;
for(int i=0; i<ds.Tables[0].Rows.Count; i++)
{
s += ds.Tables[0].Rows[i][0].ToString();
}
this.sqlConnection1.Close();
this.textBox1.Text = s;
XmlTextReader r = new XmlTextReader(new System.IO.StringReader(s));
r.Read();

HTH. If anything is unclear, please feel free to reply to the post.

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

Nov 12 '05 #2
Hello Kevin ,

First you understood my need very well :-)
2nd 10x for your answer

BUT , i would like to take my question forward ,

i don't want to use dataset .
i have stored procedure that return XML and not recordset .
i m getting the xml from the sp into some XmlReader
and i m building the XML string by looping on the XmlReader .

this is the code ,
Dim cmd As New SqlCommand()

Dim xmlr As XmlReader

Dim sMyXml As String

REM -- CREATE A COMMAND TEXT AND OPEN THE CONNECTION

cmd.Connection = m_Conn ' connection

cmd.CommandType = CommandType.Text

cmd.CommandText = sSqlStatement ' some stored procedure that return an
XML .

xmlr = cmd.ExecuteXmlReader

xmlr.Read()

Do While xmlr.ReadState <> xmlr.ReadState.EndOfFile

sMyXml = sMyXml & xmlr.ReadOuterXml().ToString

Loop

xmlr.Close()

But the problem is that in some of my SP's I m getting the following error

Invalid attempt to GetBytes on column ''. The GetBytes function can only be
used on columns of type Text, NText, or Image.

And in other SP's every thing ok !

So my questions are

1) is it the best way to build an XML string with out using DataSet ?

2) why I m getting this invalid Error on some of my SP's and what
doe's it mean ?

10x
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:oL*************@cpmsftngxa10.phx.gbl...
Hi Tiraman,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get the Xml results from a
SQL stored procedure. If there is any misunderstanding, please feel free to let me know.

I think we can get the Xml data from the database and fill them to a
DataSet. Then, we join all the strings in the table to form a complete xml
document. We can use an XmlTextReader to read it. Here is a code snippet
for your reference.

this.sqlConnection1.Open();
SqlDataAdapter sda = new SqlDataAdapter("GetEmployeeXml",
this.sqlConnection1);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
sda.Fill(ds);
string s = string.Empty;
for(int i=0; i<ds.Tables[0].Rows.Count; i++)
{
s += ds.Tables[0].Rows[i][0].ToString();
}
this.sqlConnection1.Close();
this.textBox1.Text = s;
XmlTextReader r = new XmlTextReader(new System.IO.StringReader(s));
r.Read();

HTH. If anything is unclear, please feel free to reply to the post.

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

Nov 12 '05 #3
Ok, If you have a StringReader object, you can easily load an XmlDocument
from it...
here is an example:

using System.Xml;
using System.IO;

StringReader reader = null;
XmlDocument xmlDoc = null;
try
{
reader = new StringReader("<doc><Element>Text node</Element></doc>");
xmlDoc = new XmlDocument();
xmlDoc.LoadXml(reader.ReadToEnd());
MessageBox.Show(xmlDoc.OuterXml);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}

"Tiraman" <ti*****@netvision.net.il> skrev i meddelandet
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello Kevin ,

First you understood my need very well :-)
2nd 10x for your answer

BUT , i would like to take my question forward ,

i don't want to use dataset .
i have stored procedure that return XML and not recordset .
i m getting the xml from the sp into some XmlReader
and i m building the XML string by looping on the XmlReader .

this is the code ,
Dim cmd As New SqlCommand()

Dim xmlr As XmlReader

Dim sMyXml As String

REM -- CREATE A COMMAND TEXT AND OPEN THE CONNECTION

cmd.Connection = m_Conn ' connection

cmd.CommandType = CommandType.Text

cmd.CommandText = sSqlStatement ' some stored procedure that return an
XML .

xmlr = cmd.ExecuteXmlReader

xmlr.Read()

Do While xmlr.ReadState <> xmlr.ReadState.EndOfFile

sMyXml = sMyXml & xmlr.ReadOuterXml().ToString

Loop

xmlr.Close()

But the problem is that in some of my SP's I m getting the following error
Invalid attempt to GetBytes on column ''. The GetBytes function can only be used on columns of type Text, NText, or Image.

And in other SP's every thing ok !

So my questions are

1) is it the best way to build an XML string with out using DataSet ?
2) why I m getting this invalid Error on some of my SP's and what
doe's it mean ?

10x
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:oL*************@cpmsftngxa10.phx.gbl...
Hi Tiraman,

First of all, I would like to confirm my understanding of your issue. From your description, I understand that you need to get the Xml results from a SQL stored procedure. If there is any misunderstanding, please feel free

to
let me know.

I think we can get the Xml data from the database and fill them to a
DataSet. Then, we join all the strings in the table to form a complete xml document. We can use an XmlTextReader to read it. Here is a code snippet
for your reference.

this.sqlConnection1.Open();
SqlDataAdapter sda = new SqlDataAdapter("GetEmployeeXml",
this.sqlConnection1);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
sda.Fill(ds);
string s = string.Empty;
for(int i=0; i<ds.Tables[0].Rows.Count; i++)
{
s += ds.Tables[0].Rows[i][0].ToString();
}
this.sqlConnection1.Close();
this.textBox1.Text = s;
XmlTextReader r = new XmlTextReader(new System.IO.StringReader(s));
r.Read();

HTH. If anything is unclear, please feel free to reply to the post.

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


Nov 12 '05 #4
Hi Tiraman,

You can also use the ExecuteXmlReader method to get the xml document.
Please check the following KB article for reference:

http://support.microsoft.com/?id=316016

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

Nov 12 '05 #5
Hi Kevin

i m using the ExecuteXmlReader method and every thing ok but for the times
which i m runnig SP's that return an XML by using the option explicit and using the CDATA in the XML

you can see more details about my problem in the other thread i added to the newsgroup
"Subject: Invalid attempt to GetBytes on column '' , Please HELP

please Advice

10x

----- Kevin Yu [MSFT] wrote: ----

Hi Tiraman

You can also use the ExecuteXmlReader method to get the xml document.
Please check the following KB article for reference

http://support.microsoft.com/?id=31601

Kevin Y
======
"This posting is provided "AS IS" with no warranties, and confers no
rights.
Nov 12 '05 #6
Hi Tiraman,

I didn't see your new post. Please try to post it with the email you have
registered. And could you please show us the SQL statement you're using to
get Xml data?

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

Nov 12 '05 #7

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

Similar topics

0
by: Kurt Watson | last post by:
I’m having a different kind of problem with Hotmail when I sign in it says, "Web Browser Software Limitations Your Current Software Will Limit Your Ability to Use Hotmail You are using a web...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
13
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
1
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and...
0
by: 2Barter.net | last post by:
newsmail@reuters.uk.ed10.net Fwd: Money for New Orleans, AL & GA Inbox Reply Reply to all Forward Print Add 2Barter.net to Contacts list Delete this message Report phishing Show original
6
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
5
by: tabani | last post by:
I wrote the program and its not giving me correct answer can any one help me with that please and specify my mistake please it will be highly appreciable... The error arrives from option 'a' it asks...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.