편집 기록

편집 기록
  • 프로필 허대영(소프트웨어융합대학)님의 편집
    날짜2016.07.21

    sqlreader에서 왜 read가 안되는지 모르겠어요


    버튼을 누르면 rows의 3번째 열의 값을 가져오는 기능을 구현중인데 , db를 읽어오지못하네요..

    private void btnSearch_Click(object sender, EventArgs e)
            {
                SqlConnection conn = new SqlConnection("Data Source=YONGCHEOL;Initial Catalog=ADO;Integrated Security=True");```
    
               conn.Open();
    
                string suzy = "SELECT * FROM rankTBL where NAME='" + txtName+ "' AND CLASS='" + ClassNum+ "'";
                SqlCommand cmd = new SqlCommand(suzy, conn);
                SqlDataReader suzyread = cmd.ExecuteReader();
    
                if (suzyread.Read())
                {
                    kor = suzyread.GetInt16(3);
                    lbEng.Text = kor.ToString();
                }
                else
                {
                    MessageBox.Show("read못함");
                }
    
                suzyread.Close();
                conn.Close();
            }
    

    if문을 지우고 실행했을때입니다. 이미지

  • 프로필 알 수 없는 사용자님의 편집
    날짜2016.07.21

    sqlreader에서 왜 read가 안되는지 모르겠어요


    버튼을 누르면 rows의 3번째 열의 값을 가져오는 기능을 구현중인데 , db를 읽어오지못하네요..

    private void btnSearch_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("Data Source=YONGCHEOL;Initial Catalog=ADO;Integrated Security=True");

           conn.Open();
    
            string suzy = "SELECT * FROM rankTBL where NAME='" + txtName+ "' AND CLASS='" + ClassNum+ "'";
            SqlCommand cmd = new SqlCommand(suzy, conn);
            SqlDataReader suzyread = cmd.ExecuteReader();
    
            if (suzyread.Read())
            {
                kor = suzyread.GetInt16(3);
                lbEng.Text = kor.ToString();
            }
            else
            {
                MessageBox.Show("read못함");
            }
    
            suzyread.Close();
            conn.Close();
        }
    if문을 지우고 실행했을때입니다.
    ![이미지][1]