473,396 Members | 2,076 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,396 software developers and data experts.

How to put retreived dataset from a webservice(to asp) into a Recordset

Hi everyone .
I had developed a webservice in .net and had called it from classic ASP.

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
Dim xmlhttp
Dim DataToSend
DataToSend="Var1="&Request.Form("text1")&"&Var2="& Request.Form("text2")
Dim postUrl
postUrl = "http://localhost/WebServiceTest/Service1.asmx/SearchProductFamily"
Set xmlhttp = server.Createobject("MSXML2.XMLHTTP")
xmlhttp.Open "POST",postUrl,false
xmlhttp.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
xmlhttp.send DataToSend
Response.Write(xmlhttp.responseText)
End if

now it returns me Response.Write(xmlhttp.responseText) which is of text type.

The output is of the form
1 ProductName1
2 ProductName2
3 ProductName3


it does not give me an xml output.

I want to get the output in the recordset form in ASP.I am new to XML and to ASP.
Plz help.
May 9 '07 #1
2 3380
The output from the webservice is :

<?xml version="1.0" encoding="utf-8" ?>
- <DataSet xmlns="http://tempuri.org/">
- <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xs:element name="NewDataSet" msdata:IsDataSet="true">
- <xs:complexType>
- <xs:choice maxOccurs="unbounded">
- <xs:element name="Table">
- <xs:complexType>
- <xs:sequence>
<xs:element name="ProductID" type="xs:int" minOccurs="0" />
<xs:element name="ProductName" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
- <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
- <NewDataSet xmlns="">
- <Table diffgr:id="Table1" msdata:rowOrder="0">
<ProductID>1</ProductID>
<ProductName>ProductName1</ProductName>
</Table>
- <Table diffgr:id="Table2" msdata:rowOrder="1">
<ProductID>2</ProductID>
<ProductName>ProductName2</ProductName>
</Table>
- <Table diffgr:id="Table3" msdata:rowOrder="2">
<ProductID>3</ProductID>
<ProductName>ProductName3</ProductName>
</Table>
</NewDataSet>
</diffgr:diffgram>
</DataSet>

but wen i retrieve from the asp , it does not give me the column names ProductID & ProductName.

It just give me the output as :

1 ProductName1
2 ProductName2
3 ProductName3
May 9 '07 #2
After research and browsing i had found the solution on the net......

<html>
<head>
<title>Calling a webservice from classic ASP</title>
</head>
<body>
<%

Public Function fnXML2RecSet(ByVal sFileName As String) As Recordset
'ex: sFileName = "c:\test.xml"
'first we call msxml object for using xml files
'to make this we have to add referance from project->referances
'microsoft xml 3.0 to use this function
'so you msxml3.0 must be installed on the machine
Dim oDom As New MSXML2.DOMDocument
'we open a blank recordset
'to make this we have to again add referance
'microsoft activeX data objects 2.5
Dim rsReturn As New Recordset
'lets set async to false to use some ability of xml
oDom.async = False
'now load the file name which given to this function
oDom.Load (sFileName)
'look to the count of the fields
For i = 0 To oDom.documentElement.childNodes(0).childNodes.leng th - 1
'append each field name in to the recordset
'but we have to build information about the fields
'i used adVarChar, 300, adFldIsNullable as default action
'this means that all fields are varchar and contains 300 characters
'and can contain null value
'you may change this settings for your needs
'maybe you can detect type of the field etc..
rsReturn.Fields.Append oDom.documentElement.childNodes(0).childNodes(i).n odeName, adVarChar, 300, adFldIsNullable
Next
'now we have a recordset containing field names
'lets open this recordset
rsReturn.Open
'now lets look how many recordset are there in the xml file
For j = 0 To oDom.documentElement.childNodes.length - 1
'add a new record
rsReturn.AddNew
'put all values of the fields into the fieldnames matches
For i = 0 To oDom.documentElement.childNodes(j).childNodes.leng th - 1
rsReturn(oDom.documentElement.childNodes(j).childN odes(i).nodeName) = oDom.documentElement.childNodes(j).childNodes(i).T ext
Next
Next
'move to the first recordset
rsReturn.MoveFirst
'return this recordset as output
Set fnXML2RecSet = rsReturn
End Function

Private Sub btnTest_Click()
'lets call the class module as rsTest we builded
Dim rsTest As New XMLConverter
'lets open a new recordset
'we will use this recordset to show the output recordset generated from xml file
Dim rs As New Recordset
Dim sFileName As String
Dim sTmpStr As String
'lets set the file name
sFileName = App.Path & "\test.xml"
'now Set the recordset to the function
'which converts xml to recordset
'we give the name of the file
Set rs = rsTest.fnXML2RecSet(sFileName)
'lets loop this recordset until end of file
Do Until rs.EOF
sTmpStr = ""
'begin from the first recordname to the last recordname
For nX = 0 To rs.Fields.Count - 1
'add the name of the recordset field and value of it
sTmpStr = sTmpStr & rs.Fields.Item(nX).Name & " = " & rs.Fields.Item(nX).Value & vbCrLf
Next
'show it
MsgBox sTmpStr
'move to the next record
rs.MoveNext
Loop
End Sub



Public Function XMLDOMToRecordset(objXMLDOM As DOMDocument) As Recordset
Dim objRS As ADODB.Recordset

Set objRS = New ADODB.Recordset
objRS.Open objXMLDOM
Set RecordsetFromXMLDocument = objRS

Set objRS = Nothing

%>
<FORM method=POST name="form1">
Enter the two Values to be Added<BR>
<INPUT type="text" name="text1">
<INPUT type="text" name="text2">
<BR><BR>
<INPUT type="submit" value="Add" name="btnTest">
</form>
</body>
</html>



Second Reference :

<html>
<head>
<title>Calling a webservice from classic ASP</title>
</head>
<body>
<%
Private Function AddSlash(ByVal sPath As String) As String
sPath = Trim(sPath)
If Len(sPath) > 0 Then
If Right$(sPath, 1) <> "/" Then
If Right$(sPath, 1) <> "\" Then
sPath = sPath & "\"
End If
End If
AddSlash = sPath
End If
End Function

Private Sub CmdToRecordset_Click()
If File1.ListIndex = -1 Then
'must select an xml file, first
MsgBox "Please, select an Xml File, first!"
Exit Sub
End If
'else you can try loading Xml

Dim xmlDoc As DOMDocument
Dim Rs As ADODB.Recordset
Set xmlDoc = getXmlFromFile(AddSlash(File1.Path) & File1.FileName)

'function return nothing
'if error occurred in loading file
If Not xmlDoc Is Nothing Then
'now transform it in a recordset
'this function from Ms seems not to work
'at least for me: it says xml is not well formed...
' Set Rs = RecordsetFromXMLDocument(xmlDoc)

'let's do it manually
Set Rs = GetRsFromXmlManual(xmlDoc)
'got it!

'show records:
Dim CountCol As Long
Dim CountRow As Long
Dim rsFld As ADODB.Field
With grdFlex
.Redraw = False
.Cols = Rs.Fields.Count
.Rows = Rs.RecordCount + 1
.FixedRows = 1
'put columns titles
For Each rsFld In Rs.Fields
.TextMatrix(CountRow, CountCol) = rsFld.Name
CountCol = CountCol + 1
Next
'now put data
CountRow = 1
Do While Not Rs.EOF
CountCol = 0
For Each rsFld In Rs.Fields
'the trim( & "") will make null equal to empty string...
.TextMatrix(CountRow, CountCol) = Trim(rsFld.Value & "")
CountCol = CountCol + 1
Next
CountRow = CountRow + 1

Rs.MoveNext
Loop
'make grid refresh
.Redraw = True
End With
End If
End Sub

Private Sub Dir1_Change()
'sinc folder and files
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
'sinc drive and folders
'an error occur if drive is not ready
On Error GoTo errHandler
Dir1.Path = Drive1.Drive
Exit Sub
errHandler:
'last known working disk
'this could be done better...
Drive1.Drive = Left$(Dir1.Path, 1) & ":"
End Sub

Private Sub Form_Load()
'show only xml files
File1.Pattern = "*.xml"
End Sub
Private Function getXmlFromFile( _
ByVal sPathName As String _
) As DOMDocument

'Private xmlDoc As DOMDocument
'Private xmlId As IXMLDOMDocumentType
Dim xmlDoc As DOMDocument
Set xmlDoc = New DOMDocument
xmlDoc.async = False
'if you hold the xml in a variable,
'use loadXml
'if not xmlDoc.loadXML(sPathName) then
'...as below...

'If instead, as here, you're loading from file or
'from url, use load

If Not xmlDoc.Load(sPathName) Then
'the load or loadXml return false if something
'goes wrong
MsgBox xmlDoc.parseError.reason 'here you hold an err.description
Set xmlDoc = Nothing
End If
Set getXmlFromFile = xmlDoc
End Function

''seems as if following does not work...
'Private Function RecordsetFromXMLDocument(ByVal XMLDOMDocument As DOMDocument) As ADODB.Recordset
' Dim Rs As ADODB.Recordset
'
' 'this is from Msdn:
' 'HOWTO: Obtain an ADO Recordset from XML
'
' Set Rs = New ADODB.Recordset
' Rs.Open XMLDOMDocument 'pass the DOM Document instance as the Source argument
'
' Set RecordsetFromXMLDocument = Rs 'return the recordset
' Set Rs = Nothing
'End Function

Private Function GetRsFromXmlManual(ByVal xmlDoc As DOMDocument) As ADODB.Recordset
'Original routine is from Planet-Source-Code.com
'at http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=7190&lngWId=4
'I added a more complex way to be sure to append all the fields needed...

Dim CountField As Long
Dim CountRecord As Long
Dim Rs As ADODB.Recordset
Dim dicFields As Scripting.Dictionary
Dim sFieldName As String

Set Rs = New ADODB.Recordset
Set dicFields = New Scripting.Dictionary

'To be sure to get all fields you need, scroll all
'and add new names to a dictionary and to recordset - choosed
'dictionary as it has a method to test for a key
'existence without making you need error handling

For CountRecord = 0 To xmlDoc.documentElement.childNodes.length - 1
'get name of field

For CountField = 0 To xmlDoc.documentElement.childNodes(CountRecord).chi ldNodes.length - 1
sFieldName = xmlDoc.documentElement.childNodes(CountRecord).chi ldNodes(CountField).nodeName
If Not dicFields.Exists(sFieldName) Then
'a non already added field name
dicFields.Add sFieldName, sFieldName

Rs.Fields.Append sFieldName, adVarChar, 300, adFldIsNullable
End If
Next
Next

'now recordset has all required fields

Rs.Open

'now lets look how many recordset are there in the xml file
For CountRecord = 0 To xmlDoc.documentElement.childNodes.length - 1
'add a new record
Rs.AddNew
'put all values of the fields into the fieldnames matches
For CountField = 0 To xmlDoc.documentElement.childNodes(CountRecord).chi ldNodes.length - 1
sFieldName = xmlDoc.documentElement.childNodes(CountRecord).chi ldNodes(CountField).nodeName
Rs(sFieldName) = xmlDoc.documentElement.childNodes(CountRecord).chi ldNodes(CountField).Text
Next
Next
'move first
Rs.MoveFirst
Set GetRsFromXmlManual = Rs
Set Rs = Nothing
End Function

%>
<FORM method=POST name="form1">
Enter the two Values to be Added<BR>
<INPUT type="text" name="text1">
<INPUT type="text" name="text2">
<BR><BR>
<INPUT type="submit" value="Add" name="submit1" >
</form>
</body>
</html>


just refer to the above methods for the solution

Hope this is helpful
May 31 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ddt | last post by:
Hi, Does any one have some sample codes or information for converting .net Dataset to ADO recordset? Thanks in advance.
1
by: Matt M | last post by:
Hey, I'm trying to pass an XML document from a webservice to another assembly. What I'd like to do is pass either an XML document or a dataset, so I figure that if I can turn the Dataset into...
9
by: Marathoner | last post by:
I am trying to convert a dataset to an ADODB.Recordset. I create the sxl file and open it in VB.NET by using: Dim rs as ADODB.Recordset rs.Open("C:\files\xslfile.xsl") I want to do this same...
2
by: trint | last post by:
I have an app that I have been using this code to fill a datagrid: DataSet ds = new DataSet("Recordset"); OleDbDataAdapter da = new OleDbDataAdapter(); // Call data adapter's Fill method to...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
2
by: Gary Townsend | last post by:
I am writing an app in vb .net that will use an XML webservice written in PHP NuSoap. I want to have the NuSoap server send a dataset to my VB .NET application i am trying to find any documentation...
1
by: Steve | last post by:
I have a windows CE application, talking to a C# WebService. In the WebService project I have created a dataset (dsJobList), and there is a web method in there which returns a fully loaded...
1
by: Jon S via DotNetMonster.com | last post by:
Hi all In short, I have a dataset that contains 10 records and the relevant headings. All I want to do is bind this dataset to a asp.net repeater control. All the examples I've seen create...
2
by: Deecrypt | last post by:
Hi, I'm a newbie to the Web Services topic. I have an ASP.NET website and am trying to send a Dataset from it to a WebService which should insert all the data from this DataSet to an Access...
5
by: Katit | last post by:
I get dataset from database. I need to take specific datatable out of it and add it to second dataset to pass back from webservice. ds.Tables.Add(dsPart.Tables); I get exception "Datatable...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.