Not getting the data using wcf service

Posted by Mandlaa under WCF on 6/6/2014 | Points: 10 | Views : 334 | Status : [Member] | Replies : 2
This is my code for getting data from database based on id


List<Cus> GetSelectedCus(int Party_Dim_Key);
public List<Cus> GetSelectedCus(int Party_Dim_Key)
List<Cus> Cuss = new List<Cus>();
using (SqlConnection con = new SqlConnection(@"<>"))

using (SqlCommand cmd = new SqlCommand("Select * from CONSUMER2 where Party_Dim_Key=@Party_Dim_Key", con))
cmd.Parameters.AddWithValue("@Party_Dim_Key", Party_Dim_Key);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
Cus cus1 = new Cus();
cus1.Party_Dim_Key = int.Parse(dr["Party_Dim_Key"].ToString());
cus1.Customer_First_Nm = Convert.ToString(dr["Customer_First_Nm"]);
cus1.Customer_Gender_Nm = dr["Customer_Gender_Nm"].ToString();

cus1.PhoneNumber = Convert.ToString(dr["PhoneNumber"]);
cus1.Address = Convert.ToString(dr["Address"]);
cus1.City = Convert.ToString(dr["City"]);
cus1.Country = Convert.ToString(dr["Country"]);
cus1.Zipcode = Convert.ToString(dr["Zipcode"]);
cus1.EmailId = Convert.ToString(dr["EmailId"]);
cus1.Tagid = Convert.ToString(dr["Tagid"]);
cus1.SNo = Convert.ToString(dr["SNo"]);

cus1.batchid = int.Parse(dr["batchid"].ToString());
cus1.ClientId = int.Parse(dr["ClientId"].ToString());
cus1.pwd = Convert.ToString(dr["pwd"]);
cus1.CouponValue = int.Parse(dr["CouponValue"].ToString());
return Cuss;

this code i am writting but i am not get any data from database

what is the mistake?

pleae correct my code


Posted by: Sheonarayan on: 6/6/2014 [Administrator] HonoraryPlatinum | Points: 25

Try to run your query in against the database in SQL Server Management Studio "Select * from CONSUMER2 where Party_Dim_Key=@Party_Dim_Key". If you are getting the data then there should be problem in the connection between your end user app and the wcf. Debug the WCF service with break point at the while loop.

On the other note, looks like you have given your original database name, username and password in the above code snippet. Replace that with some fake names to avoid security breach or spam attacks.


Sheo Narayan

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mandlaa on: 6/6/2014 [Member] Starter | Points: 25

plz give me solution for this one

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response