SqlConnection con5 = dataOperate.createCon();
                con5.Open();
                SqlCommand com5 = new SqlCommand("select 赔偿比例 from 损坏赔偿 where 损坏程度='" + DropDownList1.SelectedValue + "'", con5);
                SqlDataReader dr5 = com5.ExecuteReader();
                dr5.Read();
                int bili =int.Parse(dr5["赔偿比例"]);
                dr5.Close();
                con5.Close();就是这里int bili =int.Parse(dr5["赔偿比例"]);转换不成功  用convert.toint32也不对  帮帮忙 谢谢了

解决方案 »

  1.   

    报什么错?if (dr5["赔偿比例"] != null)
    {
        int bili = Convert.ToInt32(dr5["赔偿比例"]);
    }
      

  2.   

    dr5["赔偿比例"]的值转换成String类型先
      

  3.   

    dr5["赔偿比例"]这个值是否是空,或者非int可转的值
      

  4.   


    if(dr5["赔偿比例"] != DBNull.Value)
    {
        int bili = int.Parse(dr5["赔偿比例"].ToString());
    }
      

  5.   


    int i = 1;
    int.TryParse(dr5["赔偿比例"].ToString(),out i);
    //你可以看看dr5["赔偿比例"]是什么样数据
    参考:http://msdn.microsoft.com/zh-cn/library/f02979c7%28v=VS.80%29.aspx
      

  6.   

    SqlConnection con5 = dataOperate.createCon();
      con5.Open();
      SqlCommand com5 = new SqlCommand("select 赔偿比例 from 损坏赔偿 where 损坏程度='" + DropDownList1.SelectedValue + "'", con5);
      SqlDataReader dr5 = com5.ExecuteReader();
      if (dr5.Read())
      int bili =int.Parse(dr5["赔偿比例"]);
      com5.Dispose();
      con5.Close();
      

  7.   

    你可以写一个方法啊,你可以实例化对象嘛,表我就用Table代替表了
     public static Table Get()
     {
      SqlConnection con5 = dataOperate.createCon();
      con5.Open();
      SqlCommand com5 = new SqlCommand("select 赔偿比例 from 损坏赔偿 where 损坏程度='" +  DropDownList1.SelectedValue + "'", con5);
      SqlDataReader dr5 = com5.ExecuteReader();
      dr5.Read();
      if(dr5.Read())
    {
      Table tb =new Table();
      tb.要求的字段(ID类型的)=int.Parse(dr5["赔偿比例"]);
      dr5.Close();
      con5.Close();
      return tb;
    }
    else
    {
      read.Close();
      return null;
    }
               
            }