Showing posts with label return. Show all posts
Showing posts with label return. Show all posts

Thursday, March 29, 2012

Pass Recordset from Web Service to Classic ASP.

I want to use the .net Web Service to create a function and return the
datas (RecordSet). And want to retrived those data on the classic ASP.
Does any body have some example of this. How to create the Recordset in
webservice and get it at classic asp.
Thanks and Regards.Ted Ngo wrote:
> I want to use the .net Web Service to create a function and return the
> datas (RecordSet). And want to retrived those data on the classic ASP.
> Does any body have some example of this. How to create the Recordset
> in webservice and get it at classic asp.
> Thanks and Regards.
See this thread:
http://groups.google.com/group/micr...29ded2e3b036cec
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
so I using this
Or, you can send the XML of the ADO recordset back, and re-construct it
on
the client. Use Interop on the server to work with the ADO recordset.
// ON THE SERVER -- Web Service
// Add references to ADODB library
// Create a stream object
myStream = new ADODB.Stream();
// Replace the constants with their actual values
recordSet.Save(myStream, adPersistXML);
output = myStream.ReadText(adReadAll);
// Return the XML string, complete with schema
return output;
To return the recorset
and then on the asp using this to get the record set
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
Is that righ?
Thanks
Yes, that's what I had in mind. Also, see Adam's last message in that
thread.
Bob
Ted Ngo wrote:
> so I using this
> Or, you can send the XML of the ADO recordset back, and re-construct
> it on
> the client. Use Interop on the server to work with the ADO recordset.
>
> // ON THE SERVER -- Web Service
> // Add references to ADODB library
>
> // Create a stream object
> myStream = new ADODB.Stream();
>
> // Replace the constants with their actual values
> recordSet.Save(myStream, adPersistXML);
> output = myStream.ReadText(adReadAll);
>
> // Return the XML string, complete with schema
> return output;
> To return the recorset
> and then on the asp using this to get the record set
> 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
> Is that righ?
> Thanks
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Wednesday, March 21, 2012

Passing a object to a reflection class

Hello,

I would like to be able to pass an object from my code behind to another class and return a string with all the object properties and values.

IE Book has Book.Title= "The grinch" Book.Author="Tom Jones"

I need to be able to do something like

GetObjectsProperties(book) book is an instance of the class Book

This would returnTitle= "The grinch" Author="Tom Jones"

I undertand I can use System.Reflection for this, however I could not find a good example.


give this a try:

Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load'one of the page properties we're going to read requires us to validate first... Page.Validate()'just as a sample, we'll pass the current page object to inspect the properties Response.Write(GetProps(Me))End Sub Private Function GetProps(ByVal targetAs Object)As String Dim propInfoArray()As System.Reflection.PropertyInfoDim resultAs New System.Text.StringBuilder'get array of propertyinfo objects for our targets Type propInfoArray = target.GetType.GetProperties'iterate through these propertyinfo objectsFor Each propInfoAs System.Reflection.PropertyInfoIn propInfoArrayDim sAs String Try s = Convert.ToString(propInfo.GetValue(target,Nothing))Catch exAs Exception s ="Error reading property"End Try result.AppendFormat("{0}=""{1}"" ", propInfo.Name, s)Next Return result.ToStringEnd Function

Hey, thanks for your help.

When converting this to C# , one line of code did not work for me. Please advise.

using System;
using System.Text;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NGB.Mobilization.Util;
using System.Reflection;

public partial class Mobilization_Default2 : NGB.GKO.WebUI.GKOPage
{
protected void Page_Load(object sender, EventArgs e)
{
userLinksControl.UserName = this.CurUser.UserName;

ArrayList excludeColumns = new ArrayList();
excludeColumns.Add("UserId");
Response.Write(GetProps(this.CurUser, excludeColumns));
}

private stringGetProps(Object target, ArrayList excludeColumns)
{
//PropertyInfo propInfoArray = new PropertyInfo();
StringBuilder result = new StringBuilder();
//get array of propertyinfo objects for our targets Type
PropertyInfo[] propInfoArray = target.GetType().GetProperties();
// iterate through these propertyinfo objects

foreach(PropertyInfo propInfo in propInfoArray)
{
// Do Not Add Excluded Columns
if (excludeColumns.Contains(propInfo.Name) == false)
{
string s;

try
{
s = propInfo.GetValue(propInfo, null).ToString();
// s = Convert.ToString(propInfo.GetValue(target, Nothing));
}
catch
{
// na
s = "Error reading property";
}
result.AppendFormat("<b>{0}</b> = {1} ", propInfo.Name, s);
}
}

return result.ToString();

}

This prints:

UserName = Error reading propertyFirstName = Error reading propertyLastName = Error reading propertyEmail = Error reading propertyState = Error reading propertyBranch = Error reading propertyDebug = Error reading property

Thanks for your helpmbanavige!



}

change it to this:

s = propInfo.GetValue(target, null).ToString();


awesome it worked. thanks man!

I'm going to make this a "helper" function for my project.

i'll post the code when it's complete