Wednesday, September 26, 2012

Get dynamic value in the service method of WCF

Get dynamic value in the service method of WCF

Hi all,

I have a service which contain the method name as GetDetails.

In this method i am making a list of all information. Like -

while (dr.Read())
{
var ele = new DetailList
{
myID= data.getInt(dr, 0),
myName = data.getString(dr, 1),
Value = Math.Abs(data.getDecimal(dr, 2)),
Total = data.getInt(dr, 3),
Value1 = data.getDecimal(dr, 4)
};
DetailList.Add(ele);
}

The above is only 5 items added in the list like myID,myName...etc. 

Suppose i want add new value LastName in this list dynamically...then wht i want to do?

Answers & Comments...

Answer: 1

Hi Shrikant,

Shrikant Gawali

The above is only 5 items added in the list like myID,myName...etc. 

Suppose i want add new value LastName in this list dynamically...then wht i want to do?

Can you explain the question more clearly? What is the relationship between the new value and WCF method?

Best Regards,



Answer: 2

See,

I have a class that contain the 5 members id,fname,mname,lname and city with their get, set properties.

In my service there is a method name as getStudDetails which can return the list of all student details.

To get the details of the student i used a procedure. This procedure can return only the updated columns not all columns.

Every time this procedure can return different columns.

In the loop i am taking value by using the following code-

da = new SqlDataAdapter("MyQuery", con);
da.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
st = new studentCls()
{
vchid = ds.Tables[0].Rows[i].ItemArray[0].ToString(),
vchfname = ds.Tables[0].Rows[i].ItemArray[1].ToString(), 
vchmname=ds.Tables[0].Rows[i].ItemArray[2].ToString(),

vchlname=ds.Tables[0].Rows[i].ItemArray[3].ToString(),

vchcity=ds.Tables[0].Rows[i].ItemArray[4].ToString(),
};
std.Add(st);
}

Here when i execute the code this can not return anything.

I want the value of the member which can be selected by the query?

What is the exact solution ?



Answer: 3

Shrikant Gawali

This procedure can return only the updated columns not all columns.

Shrikant Gawali

Here when i execute the code this can not return anything.

Do you try to set a breakpoint to diagnose in which line it lost the datas? A blog for your reference:

#Stored Procedure in WCF Data Service

http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/stored-procedure-in-wcf-data-service/

Best Regards,



Answer: 4

I am not getting the result because i am executing the procedure which can select only one,two,three..etc column at a time not the all column and in my loop there is 5 fields.

I want to implement the code as if procedure select 2 columns then also i want the result and if procedure select 5 columns then also it want to work...so wht is the solution?





No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog