2014-04-10 3 views
0

두 번째 쿼리에서 값을 반환 할 수 없습니다. 코드의 부 ... Mysql에서 select 쿼리의 두 번째 결과 C#

MySqlConnectionStringBuilder mysqlSB = new MySqlConnectionStringBuilder(); 
       mysqlSB.Server = "localhost"; 
       mysqlSB.Database = "test"; 
       mysqlSB.UserID = "admin"; 
       mysqlSB.Password = "1111"; 


       MySqlConnection con = new MySqlConnection(); 
       con.ConnectionString = mysqlSB.ConnectionString; 

       MySqlCommand Select = new MySqlCommand("select name from table_1 where id='1' ", con);  
       MySqlDataReader myReader; 
       con.Open(); 
       myReader = Select.ExecuteReader(); 

       while (myReader.Read()) 
      { 
       count++; 
      } 
      string name = myReader["name"].ToString(); 

    if (count == 1) 
       { 

        MySqlCommand Select2 = new MySqlCommand("select country from table_2 where name='"+name+"'", con); 
        MySqlDataReader myReader2; 
        myReader2 = Select2.ExecuteReader(); 
        while (myReader2.Read()) 
        { 
         count++; 
        } 

        return myReader2["id"].ToString(); 
       } 

내가 두 번째 부분을 삭제하면

, 후 (== 1 카운트)와 이름을 반환 = 모두 좋아하지만, 내가 돌아올 때 ID가 오류가됩니다. Plase 쿼리의 두 번째, 세 번째 ... 값을 반환해야하기 때문에 이유를 말해주십시오. 감사합니다.

답변

0

내가 당신이라면 나는

Connecting to a Mysql DB with C# - Need some with Datasets

난 당신이 당신이 밖으로 선택한 국가들과 뭘 원하는지 모르는

하지만 경우 여기를 참조하십시오 쿼리의 결과를 데이터 테이블을 채우는 것 그것의 데이터 테이블에 다음 당신은 그것을 드롭 다운이나 무언가에 바인딩 할 수 있습니다

0

두 번째 당신은 ID 필드를 반환하고 데이터베이스에서 국가 필드를 선택하고 있습니다. 따라서 오류에서 읽을 수있는 ID 필드를 반환하지 않습니다.

관련 문제