pass array object to web service

8 views
Skip to first unread message

shree

unread,
Dec 28, 2009, 5:35:29 AM12/28/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
hello folks ,

hope you all doing well ,

can I pass array object to from javascript to database and vice versa

can we achieve it by using web service . If any one know please let me
know ...

Cerebrus

unread,
Dec 28, 2009, 8:39:03 AM12/28/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
A Javascript array is vastly different from an array understood by the
CLR. As for most databases, I don't think they understand arrays at
all.

Gunawan Hadikusumo

unread,
Dec 28, 2009, 10:15:29 PM12/28/09
to dotnetde...@googlegroups.com
USE JSON.................. the only way

vinay kumar

unread,
Dec 28, 2009, 10:22:08 AM12/28/09
to dotnetde...@googlegroups.com

<%@ Page Language="VB" AutoEventWireup="false"

CodeFile="Default.aspx.vb" Inherits="_Default" %>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Customer Details</title>

<script type="text/javascript">

function GetCustomer(){

var customerCode = document.forms[0].TextBox1.value;

UseCallback(customerCode, "");

}

function GetCustDetailsFromServer(result, context){

var i = result.split("|");

customerID.innerHTML = i[0];

companyName.innerHTML = i[1];

contactName.innerHTML = i[2];

contactTitle.innerHTML = i[3];

address.innerHTML = i[4];

city.innerHTML = i[5];

region.innerHTML = i[6];

postalCode.innerHTML = i[7];

country.innerHTML = i[8];

phone.innerHTML = i[9];

fax.innerHTML = i[10];

}

</script>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp;

<input id="Button1" type="button" value="Get Customer Details"

onclick="GetCustomer()" /><br />

<br />

<table cellspacing="0" cellpadding="4" rules="all" border="1"

id="DetailsView1"

style="background-color:White;border-color:#3366CC;border-width:1px;

border-style:None;height:50px;width:400px;border-collapse:collapse;">

<tr style="color:#003399;background-color:White;">

<td>CustomerID</td><td><span id="customerID" /></td>

</tr><tr style="color:#003399;background-color:White;">

<td>CompanyName</td><td><span id="companyName" /></td>

</tr><tr style="color:#003399;background-color:White;">

<td>ContactName</td><td><span id="contactName" /></td>

</tr><tr style="color:#003399;background-color:White;">

<td>ContactTitle</td><td><span id="contactTitle" /></td>

</tr><tr style="color:#003399;background-color:White;">

<td>Address</td><td><span id="address" /></td>

</tr><tr style="color:#003399;background-color:White;">

<td>City</td><td><span id="city" /></td>

</tr><tr style="color:#003399;background-color:White;">

<td>Region</td><td><span id="region" /></td>

</tr><tr style="color:#003399;background-color:White;">

<td>PostalCode</td><td><span id="postalCode" /></td>

</tr><tr style="color:#003399;background-color:White;">

<td>Country</td><td><span id="country" /></td>

</tr><tr style="color:#003399;background-color:White;">

<td>Phone</td><td><span id="phone" /></td>

</tr><tr style="color:#003399;background-color:White;">

<td>Fax</td><td><span id="fax" /></td>

</tr>

</table>

</div>

</form>

</body>

</html>

Imports System.Data

Imports System.Data.SqlClient

Partial Class _Default

Inherits System.Web.UI.Page

Implements System.Web.UI.ICallbackEventHandler

Dim _callbackResult As String = Nothing

Public Function GetCallbackResult() As String _

Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult

Return _callbackResult

End Function

Public Sub RaiseCallbackEvent(ByVal eventArgument As String) _

Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent

Dim conn As SqlConnection = New _

SqlConnection("Data Source=.;Initial Catalog=Northwind;User ID=sa")

Dim cmd As SqlCommand = New _

SqlCommand("Select * From Customers Where CustomerID = ’" & _

eventArgument & "’", conn)

conn.Open()

Dim MyReader As SqlDataReader

MyReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

Dim MyValues(10) As String

While MyReader.Read()

MyValues(0) = MyReader("CustomerID").ToString()

MyValues(1) = MyReader("CompanyName").ToString()

MyValues(2) = MyReader("ContactName").ToString()

MyValues(3) = MyReader("ContactTitle").ToString()

MyValues(4) = MyReader("Address").ToString()

MyValues(5) = MyReader("City").ToString()

MyValues(6) = MyReader("Region").ToString()

MyValues(7) = MyReader("PostalCode").ToString()

MyValues(8) = MyReader("Country").ToString()

MyValues(9) = MyReader("Phone").ToString()

MyValues(10) = MyReader("Fax").ToString()

End While

Conn.Close()

_callbackResult = String.Join("|", MyValues)

End Sub

Protected Sub Page_Load(ByVal sender As Object, _

ByVal e As System.EventArgs) Handles Me.Load

Dim cbReference As String = _

Page.ClientScript.GetCallbackEventReference(Me, "arg", _

"GetCustDetailsFromServer", "context")

Dim cbScript As String = "function UseCallback(arg, context)" & _

"{" & cbReference & ";" & "}"

Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), _

"UseCallback", cbScript, True)

End Sub

End Class

check this some what helpful

ѕняєє мα∂α

unread,
Dec 29, 2009, 4:52:52 AM12/29/09
to dotnetde...@googlegroups.com
hi 
thanx for reply vinay 
I guess here you are passing just one value to the UseCallback function what i want is how can i pass a object array & return the same object array 

my object is like as follows 

function DDElements(Name,Type,Height,Width,X,Y,PageNumber)
        {
            this.name = Name;
            this.type = Type;
            this.height = Height;
            this.widht = Width;
            this.x = X;
            this.y = Y;
            this.pageNo = PageNumber;
        } 

var element = new DDElements(key,"sign",dd.elements[key].w,dd.elements[key].h,dd.elements[key].x,dd.elements[key].y,indexArray[key]);

after this code I am creating a array 
that array i want to pass it to web service method 



Thanks & Regards,
Shrinivas Mada,

vinay kumar

unread,
Dec 30, 2009, 2:08:33 AM12/30/09
to dotnetde...@googlegroups.com
 
 
and one more this through jquery

2009/12/29 ѕняєє мα∂α <shre...@gmail.com>

vinay kumar

unread,
Dec 30, 2009, 2:15:58 AM12/30/09
to dotnetde...@googlegroups.com
We  can pass array as parameter as
String [10] VALUES;
 
function array returnarrayvalues(array Variablename)
{
 
 
}

2009/12/29 ѕняєє мα∂α <shre...@gmail.com>
hi 

ѕняєє мα∂α

unread,
Dec 31, 2009, 1:42:17 AM12/31/09
to dotnetde...@googlegroups.com
hi 
thanx for reply 
yes i tryed it by array its working pretty cool dude .....

but if we can pass object to the web service its very feasible 
because i again i need to do the reverse case also ..


Thanks & Regards,
Shrinivas Mada,




vinay kumar

unread,
Dec 31, 2009, 5:42:33 AM12/31/09
to dotnetde...@googlegroups.com
create properties for all those 
 get n set them
 
2009/12/31 ѕняєє мα∂α <shre...@gmail.com>

ѕняєє мα∂α

unread,
Jan 4, 2010, 7:53:08 AM1/4/10
to dotnetde...@googlegroups.com
hey vinay thanx it works 


Thanks & Regards,
Shrinivas Mada,




vinay kumar

unread,
Jan 5, 2010, 2:06:06 AM1/5/10
to dotnetde...@googlegroups.com
do u used properties
its ok mention not

2010/1/4 ѕняєє мα∂α <shre...@gmail.com>
Reply all
Reply to author
Forward
0 new messages