日期:2014-05-18  浏览次数:20480 次

无法将类型“object”隐式转换为“string”??
string con = ConfigurationSettings.AppSettings["mc"];
  SqlConnection mycon = new SqlConnection(con);
   
  SqlCommand mycom = new SqlCommand("select * from bjb where 班级号=@classnom ", mycon);

  mycom.Parameters.Add("@classnom", SqlDbType.Char);
  string novalue = TextBox1.Text.Trim();
  mycom.Parameters["@classnom"].Value = novalue;
  mycon.Open();
  SqlDataReader dr = mycom.ExecuteReader();
   
  if (dr.Read())
  {
  Label1.Text = dr["班级名"];//无法将类型“object”隐式转换为“string”。存在一个显式转换(是否缺少强制转换?)
   
  }

这是怎么回事呀,object是什么类型?

------解决方案--------------------
Label1.Text = dr["班级名"].ToString();
------解决方案--------------------
Label1.Text = dr["班级名"].ToString();
------解决方案--------------------
Label1.Text = dr["班级名"].toString();
------解决方案--------------------
dr["班级名"] 是一个Object类型 而Label1.Text需要赋一个string类型 object不能强制装换成string