If datareader.Read() Then
label1.Text = datareader("xxx")

解决方案 »

  1.   

    也就是说,从数据库中取任何值都要用SqlDataAdapter或DataReader,对吗?
      

  2.   

    不对,可以直接用sqlcommand.ExecuteScalar
      

  3.   

    SqlDataReader myReader;
    try
    {
        sensConnection.Open();
        myReader=comSonType.ExecuteReader();
        while(myReader.Read())
         {
            Label1.Text=myReader.GetValue(0).ToString();
          }
         myReader.Close();
         sensConnection.Close();
    }
    catch
    {
    }
      

  4.   

    string comSonTypeString="select count(newsTypeId) from news where newsTypeId=1100" ;
    SqlCommand comSonType =new SqlCommand(comSonTypeString,sensConnection);
    SqlDataReader dr=comSonType.ExecuteDataReader();
    if(dr.Read())
        label1.Text = dr[0].ToString();
    dr.Close;
    //注意,数据阅读器一定要随时关闭