string u = "select xxx from xx";
            SqlDataReader ureader;            SqlCommand uaCommand = new SqlCommand(u, aaConnetion);            aaConnetion.Open();
            ureader = uaCommand.ExecuteReader();
            ureader.Read();
            label17.Text = ureader.GetString(0);
            aaConnetion.Close();
            if (label17.Text == "非常重要")
                d = 90;
            else if (label17.Text == "重要")
                d = 75;
            else if (label17.Text == "一般")
                d = 60;
            else if (label17.Text == "及格")
                d = 45;
            else
                d = 15;
数据库调用内容后,用label17.Text显示调用内容,再根据调用内容的,判断d的值,我这有错误,请高手指点

解决方案 »

  1.   

    按照习惯好象少一个ureader.Close()
      

  2.   

    string u = "select xxx from xx";
    SqlCommand uaCommand = new SqlCommand(u, aaConnetion);aaConnetion.Open();
    object obj = uaCommand.ExecuteScalar();
    if (obj != null)
    {
    label17.Text = obj.ToString();
    }
    aaConnetion.Close();
    if (label17.Text == "非常重要")
    d = 90;
    else if (label17.Text == "重要")
    d = 75;
    else if (label17.Text == "一般")
    d = 60;
    else if (label17.Text == "及格")
    d = 45;
    else
    d = 15;
      

  3.   

    也要确保能读到吧`
    while (ureader.Read())
    {
        label17.Text = ureader[0].ToString();
    }
      

  4.   

    if (label17.Text == "非常重要")
      d = 90;
      else if (label17.Text == "重要")
      d = 75;
      else if (label17.Text == "一般")
      d = 60;
      else if (label17.Text == "及格")
      d = 45;
      else
      d = 15;
    每次执行if语句,答案都是 d=15  ;
      

  5.   

    在读到的前提后
    字符串的比较要做如下格式操作好一点.  if (label17.Text == "非常重要")// 
    改为 label7.Text.Trim() == "非常重要"这样试试