返回时仅获取1值 [英] Getting Only 1 Value When I Am Returning
问题描述
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;
}
}
}
这是我使用的代码,但返回列表时我仅获得ID值而不获取companyrefid.如何同时获取两者?使用断点检查我获取了ID值和companyrefrid.
http://www.c-sharpcorner.com/Forums/Thread/257265/getting-only-1-value.aspx [ ^ ]请参考此链接,我无法在此处发布图像
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
推荐答案
更改
c1.companyrefid = (Guid)reader["CompanyRefId"];
到
to
c1.companyrefid = reader.GetGuid(reader.GetOrdinal("CompanyRefId"));
或
OR
c1.companyrefid = new Guid(reader.GetString(reader.GetOrdinal("CompanyRefId")));
如果您没有从Web服务客户端获取guid值,请尝试将以下属性添加到Web服务类
if you not getting guid values from web service client side, try by adding below attribute to web service class
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
参考: ^ ]
reference:WCF service service returning GUID fails with VB.net c[^]
公司编号是什么.
它是向导吗?如果打算将GUID仅用于显示目的,请将其转换为字符串并返回.
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.
我已经在wcf中写入了类文件,但是我忘记为companyrefid设置[数据成员]
i have writen class file in wcf and i forgot to set [data member] for companyrefid
这篇关于返回时仅获取1值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!