locked
Not getting the data using wcf service RRS feed

  • Question

  • User-1070902567 posted

    This is my code for getting data from database based on id

    Interface

    [OperationContract]
    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))
                    {
                        con.Open();
                        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());
                            Cuss.Add(cus1);
                        }
                        con.Close();
                        return Cuss;
                    }
                }

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

    what is the mistake?

    pleae correct my code

    Thursday, June 5, 2014 1:10 PM

All replies

  • User-608283337 posted

    you can modify your code somewhat like this and try again. hope this helps. Plus, make sure you are pointing to the right database as well before running your code :-)

    using (SqlCommand cmd = new SqlCommand("Select * from CONSUMER2 where Party_Dim_Key=" + Party_Dim_Key.ToString(), con))
                    {
                        con.Open();
                        cmd.Parameters.AddWithValue("@Party_Dim_Key", Party_Dim_Key); // Comment out this line
    Thursday, June 5, 2014 2:17 PM
  • User-1070902567 posted

    Also not working

    Thursday, June 5, 2014 2:34 PM
  • User-417640953 posted

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

    Hi ANILBABU,

    Thank you post the issue to asp.net forum.

    That seems the simple issue about C# code for reading data from database using SqlDataReader.

    I suggest you taking a look at below points.

    # Make sure the int "Party_Dim_Key" you passed has a corresponding record in database table.

    # You can try to debug those code and how to debug WCF Apps, please follow below.

    http://www.codeproject.com/Articles/17258/Debugging-WCF-Apps

    http://msdn.microsoft.com/en-us/library/bb514135.aspx

    Hope that helps, thanks.

    Regards!

    Friday, June 6, 2014 4:40 AM
  • User-1070902567 posted

    Yes, "Party_Dim_Key" correcponding record is thier in my table.

    Friday, June 6, 2014 7:13 AM
  • User724169276 posted

    Also not working

    Make sure your connection strings are correct and how you are consuming this wcf service ?

    Friday, June 6, 2014 7:44 AM
  • User-1070902567 posted

    All are correct,Remaning all operations working perfectly,

    Only this operation not working

    I am not consuming this service any application,

    I am testing this service using "WCFStrom" test client

    Friday, June 6, 2014 7:49 AM