Click here to Skip to main content
16,012,508 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C#
public List<customer> login(string salesmanname, string usercode)
{
    List<customer> customers = new List<customer>();
    con.Open();
    using (SqlCommand cmd = new SqlCommand("Select Id, CompanyRefId from SalesMan where salesmanname=@salesmanname and code=@usercode", con))
    {
        cmd.Parameters.AddWithValue("@salesmanname", salesmanname);
        cmd.Parameters.AddWithValue("@usercode", usercode);
        using (SqlDataReader reader = cmd.ExecuteReader())
        {
            while (reader.Read())
            {
                customer c1 = new customer();
                c1.id = (int)reader["Id"];
                c1.companyrefid = (Guid)reader["CompanyRefId"];
                customers.Add(c1);             
            }
            return customers;
        }
    }
}

this is the code i have used but i am getting only id value and not companyrefid while returning in list .how to get both ?.using break point i checked i am getting id value and companyrefrid.
http://www.c-sharpcorner.com/Forums/Thread/257265/getting-only-1-value.aspx[^]please refer this link i am not able to post images here
Posted
Updated 31-May-14 20:22pm
v3
Comments
DamithSL 1-Jun-14 1:47am    
what is the column type of CompanyRefId in your database?
Nandhini Devi 1-Jun-14 1:49am    
there is no problem in refid .i am getting value while returning only id value i am getting
DamithSL 1-Jun-14 1:50am    
I ask for the type, is it Uniqueidentifier or varchar?
you can cast to GUID if you have Uniqueidentifier column
it will fail if you have some other type
Nandhini Devi 1-Jun-14 1:51am    
guid
Nandhini Devi 1-Jun-14 2:03am    
guid only i have used and can u please refer this link .not able to post image here
http://www.c-sharpcorner.com/Forums/Thread/257265/getting-only-1-value.aspx

change
C#
c1.companyrefid = (Guid)reader["CompanyRefId"];

to
C#
c1.companyrefid = reader.GetGuid(reader.GetOrdinal("CompanyRefId"));

OR
C#
c1.companyrefid = new Guid(reader.GetString(reader.GetOrdinal("CompanyRefId")));


if you not getting guid values from web service client side, try by adding below attribute to web service class
C#
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]

reference:WCF service service returning GUID fails with VB.net c[^]
 
Share this answer
 
v2
What is the type of companyrefid.
Is it a guid? Convert it to a string and return it if you plan to use the GUID for display only purposes.
 
Share this answer
 
i have writen class file in wcf and i forgot to set [data member] for companyrefid
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900