Asp.net 错误:无法隐式转换类型';int?&x27;至';字符串';
错误:无法将类型“int”隐式转换为“string”错误:无法 将类型“int”隐式转换为“string”错误:无法隐式 将类型“int”转换为“string”错误:无法隐式转换类型 “int?”转换为“string”错误:无法将类型“int”隐式转换为 “字符串”Asp.net 错误:无法隐式转换类型';int?&x27;至';字符串';,asp.net,c#-4.0,Asp.net,C# 4.0,错误:无法将类型“int”隐式转换为“string”错误:无法 将类型“int”隐式转换为“string”错误:无法隐式 将类型“int”转换为“string”错误:无法隐式转换类型 “int?”转换为“string”错误:无法将类型“int”隐式转换为 “字符串” 我想错误是从:oid=Convert.ToInt32(as1.oid) 下次请务必多解释一点 据我所知,int值可以为null,因此除非使用该值,否则不能强制转换它,否则它将给出null指针异常: public void selec
我想错误是从:oid=Convert.ToInt32(as1.oid) 下次请务必多解释一点 据我所知,int值可以为null,因此除非使用该值,否则不能强制转换它,否则它将给出null指针异常:
public void selectqueryasso()
{
CustomerOrderResult cso=new CustomerOrderResult();
var asso = from as1 in ds.orders
from as2 in ds.order_details
where (as1.oid == as2.oid)
orderby as1.pname
select new CustomerOrderResult
{
oid = Convert.ToInt32(as1.oid),
cmny =as1.cmny,
ocountry=as1.ocountry,
pname=as1.pname,
price=as1.price,
orderno=as1.orderno,
saltitle=as1.saltitle,
};
GridView1.DataSource = asso;
GridView1.DataBind();
}
因此,不要使用as1.oid,而是使用as1.oid.Value
还应检查该值是否为空:
oid = Convert.ToInt32(as1.oid.Value),
因此,您是否介意向我们展示
CustomerOrderResult
,并提及ds.orders
中的类型?
if(as1.oid.HasValue)