要确保ds.Tables[0].Rows[0]["ISTOWEB"]里面的值可以转换成整数类型
可以用Int32.TryParse先判断下

解决方案 »

  1.   

    你先要 convert.isdbnull判断一下.
      

  2.   

    请问楼上 这个Int32.TryParse怎么用?一个参数s,另一个参数out in resule是什么东东?
    那我这段代码应该怎么改?谢谢。。麻烦了。
      

  3.   

    this.dgvMarkArtile.Rows[0].Cells["ISTOWEB"].Value  这是个数字你负责付的字符串 所以报错了你可以将 ds 增加一列来负责 否跟是 显示的时候就绑定 这一列就OK了
      

  4.   


    sda.Fill(ds);
    DataColumn dc=null;
    dc=ds.Tables[0].Columns.Add("num",Type.GetType("System.String"));
    dc=ds.Tables[0].Columns.Add("type",Type.GetType("System.String"));
    dc=ds.Tables[0].Columns.Add("statex",Type.GetType("System.String"));
    for(int i=0;i<ds.Tables[0].Rows.Count;i++)
    {
    ds.Tables[0].Rows[i]["num"]=i+1;
    ds.Tables[0].Rows[i]["statex"]="终结";
    string type =ds.Tables[0].Rows[i]["scyx00635"].ToString();
    if(type=="1")
    {
    ds.Tables[0].Rows[i]["type"]="电气一票";
    }
    else if(type=="2")
    {
    ds.Tables[0].Rows[i]["type"]="电气二票";
    }
      

  5.   

    dgvMarkArtile.Rows[0].Cells["ISTOWEB"]的数据类型 应该是 int 类型吧你在这里赋值给个字符串类型  貌似不行
      

  6.   

    8楼的这位朋友。
           你这个ds.Tables[0].Rows[i]["type"]="电气一票";  开始也是int类型吗?
      

  7.   

    8楼这位朋友
       你这个ds.Tables[0].Rows[i]["type"]="电气一票";  开始也是int类型吗?
      我按照你这个方法还是不行啊。。
      

  8.   

    这个都不会用。楼主太令人蛋疼了。
    判断的是否==0的时候看看ds.Tables[0].Rows[0]["ISTOWEB"]是不是DBNULL吧。