Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 错误:无法隐式转换类型';int?&x27;至';字符串';_Asp.net_C# 4.0 - Fatal编程技术网

Asp.net 错误:无法隐式转换类型';int?&x27;至';字符串';

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

错误:无法将类型“int”隐式转换为“string”错误:无法 将类型“int”隐式转换为“string”错误:无法隐式 将类型“int”转换为“string”错误:无法隐式转换类型 “int?”转换为“string”错误:无法将类型“int”隐式转换为 “字符串”


我想错误是从: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)