[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Get data fron XML field

Posted on 2008-10-07
19
Medium Priority
?
628 Views
Last Modified: 2012-08-13
Hi,

How to read data from XML field with ADO Recordset:Fieldget and write data with Recordset:Fieldput ?

Below the SQL script to create the data sample :
CREATE TABLE test
(
  fldtest XML
);
INSERT INTO test (fldtest) VALUES ('<?xml version="1.0" encoding="windows-1252"?><E0><E01 LT="N">6.000000</E01></E0>');

Thanks in advance,

Phil
0
Comment
Question by:s2000_com
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 2
  • +2
19 Comments
 
LVL 5

Expert Comment

by:almander
ID: 23008506
Hi Phil,

I assume you are using VB, since you are talking about ADO.

Also it sounds like you want to create a new recordset based upon the data in an xml field. I.E.
Use the data in test.fieldtest to create a recordset.

If so you could call the attached RecordsetFromXMLString passing in the text in test.fieldtest.

Public Function RecordsetFromXMLString(sXML As String) As Recordset
 
    Dim oStream As ADODB.Stream
    Set oStream = New ADODB.Stream
    
    oStream.Open
    oStream.WriteText sXML   'Give the XML string to the ADO Stream
 
    oStream.Position = 0    'Set the stream position to the start
 
    Dim oRecordset As ADODB.Recordset
    Set oRecordset = New ADODB.Recordset
       
    oRecordset.Open oStream    'Open a recordset from the stream
 
    oStream.Close
    Set oStream = Nothing
 
    Set RecordsetFromXMLString = oRecordset  'Return the recordset
 
    Set oRecordset = Nothing
 
End Function

Open in new window

0
 

Author Comment

by:s2000_com
ID: 23011583
Hi almander,

I've seen this piece of code already on internet but was not able to apply to my sample: Can you show me how to do using my sample ?

TIA,

Phil
0
 
LVL 5

Expert Comment

by:almander
ID: 23015216
Can you attach your sample vb app.
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

Author Comment

by:s2000_com
ID: 23148977
almander,

I don't have any vb sample. What I mean by "my sample" is the SQL script above.

Can you show how to code using my SQL script sample above ?
0
 
LVL 85
ID: 23363075
Your question isn't clear; your sample, of course, creates a Table and inserts a single value in that Table ... from that point, what are you trying to do? And what environment will you be working?
0
 

Author Comment

by:s2000_com
ID: 23364394
Hi LSMConsulting !

I'm trying to know how to read (and optionally write) the XML field with ADO Recordset like shown in the code snippet.
set conn = Server.CreateObject("ADODB.Connection")
set rs = Server.CreateObject("ADODB.Recordset")
 
rs.open "Select * from test", conn
 
response.write(rs.Fields(0).Value)

Open in new window

0
 
LVL 85
ID: 23365440
But you're pulling this from a Table, not an XML file ... I realize that your Fields(0) would contain a portion of an XML file, but is that what you need to get? The value from that portion?
0
 

Author Comment

by:s2000_com
ID: 23370789
Yes the field is XML type containing XML data and I need to read and write it with ADO.
0
 
LVL 18

Expert Comment

by:mdougan
ID: 23739119
Well, the big question for me was whether ADO could support the new SQL Server xml data type.  Just browsed Microsoft and they say ADO 2.0 does (so, might depend on what version of Visual Studio/VB you are working with).

Anyway, this link has some great examples:

http://msdn.microsoft.com/en-us/library/ms971534.aspx

0
 
LVL 18

Expert Comment

by:mdougan
ID: 23739174
looks like their code samples are in C# but it is pretty easy to convert to VB from C# syntax... let me know if you need help with that.
0
 
LVL 39

Expert Comment

by:abel
ID: 23739571
I must say that it is a bit vague what this is about, but since this question has been open so long and several experts have given it a try to no avail, let me first try get the question clear.

Situation: a table with a (single) data field (text/varchar/xml?) is filled with XML data (assumption: it is XML compliant, assumption: XML type data field).

Request:

  1. getting this data out there using a language, VB, using a technique, ADO.
  2. getting data into that field or in a new record
  3. changing data in that field
Why the request originally states FieldGet/Put I don't know, personally, it seems that any valid approach from VB.NET would do. No wait!. The 2nd sample looks more like VBScript, which would explain the ADO approach. As has already been stated by MDougan, you'll need at least ADO 2.0 for it to work.

Can the OP verify this rephrasing of the question? And is ADO 2.0 an option?
0
 

Author Comment

by:s2000_com
ID: 23740134
mdougan: I'm still using ADO 2.8 and NOT ADO.NET. Have you some samples using ADO 2.8 ?

abel: as written in my first post, it's an XML data field and as replied to mdougan, I'm still using ADO 2.8 and not ADO.NET

Can you both confirm that it's NOT possible to do this operation with ADO 2.8 (not ADO.NET) ?
0
 
LVL 18

Accepted Solution

by:
mdougan earned 1500 total points
ID: 23740499
s2000 com
I'll research on the ADO 2.8 vs ADO.NET, but my first impression would be that only ADO.NET would support it.  The XML data type is new to MS SQL Server 2005, and it is hard enough to get Microsoft to support that in .NET much less any other environments.

So, what are you coding in?  VB6?  Don't get me wrong, I love VB6, but, you can't expect Microsoft to do timely support for their older environments.

Abel and the other experts... I don't think s2000 com's question was unclear at all.  SQL Server 2005 now has a data type called XML which has different access methods than text fields.  Most of us are used to stuffing XML into text fields, and so, this question throws us off a bit... but, if you read the question carefully, you can understand what is being asked.
0
 

Author Comment

by:s2000_com
ID: 23740779
Thanks mdougan to support me in my quest !

We are using Visual-Objects ( http://www.cavo.com) which is a Win32 (not .NET) language and are in a migration project from xBase to SQL Server thru ADO 2.8. In xBase we have stored XML data in memo (text) fields for 4 years now. During the migration to SQL Server (some months ago) we tried to store XML data in XML fields (logic !). Finally, at that time, we decided to store XML in varchar(max) but I've continued my research upto now. From September 2009, we will migrate our code to Vulcan.NET (www.govulcan.net). So it seems that we will migrate the XML data from VARCHAR(MAX) field to XML field at that time.

If you have more infos about ur research, thanks to let me know. Anyway as you were the only one who uinderstand my request : points are for you.
0
 
LVL 39

Expert Comment

by:abel
ID: 23742427
> I don't think s2000 com's question was unclear at all.

Maybe not, but if people re-read the whole thread after the question had been silent for a month, and if you see from some of the posts that there is some unclarity (and I don't know how often the question was updated) I tried to wrap it up.

But on second thought (and in the morning, not late at night) you are right, the question itself is clear ;)

And on third thought: that final comment of the OP makes everything much more crystal clear on what actually is the task at hand and would allow us to help more to the point. Though this question is closed, you (the OP) might want to put that last comment into a new question as quite some people can give you hints on how to tackle that task :)
0
 

Author Comment

by:s2000_com
ID: 23742505
abel: Thanks for the advice. For my next requests, I will explain more the situation, causes and consequences.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question