2011-10-30 2 views
2

세 가지 대답이있는 쿼리에 대해 세 개의 텍스트 상자에 표시하려는 것과 같이 SQL 쿼리 결과를 텍스트 상자에 표시하려면 어떻게합니까? ExecuteScalar 또는 Listbox 또는 레코드 세트를 사용할 수 있습니까? 어떻게해야합니까? 내가 루프를 사용해야한다고 생각하지만 어떻게?개별 텍스트 상자에 쿼리 값 표시

+0

어떤 데이터베이스를 사용하십니까? – Sandy

답변

1

If you are executing a SQL command that returns a result, such as executing a SELECT statement you will have to use a different method. The SqlCommand's ExecuteReader method returns a SqlDataReader object that contains all of the records retrieved after executing the SQL command.

try 
{ 
    SqlDataReader dr; 
    dbCon.Open(); 

//write your select statement here..... 
    dr = sqlcom.ExecuteReader(); 
    if(dr.HasRows == True) 
    { 
    txt_clientID.Text = ((Integer) dr["cID"]).ToString(); 
    txt_clientAddress.Text = (String) dr["cAddress"]; 
    txt_clientPhoneNumber.Text = (String) dr["cPhoneNumber"]; 
    } 
    dr.Close(); 
    dbCon.Close(); 
} 
catch(Exception ex) 
{} 
+0

Microsoft SQL Server를 사용하여 ExecuteReader() –

+0

@KatyJ r을 인식 할 수 없습니까? –

관련 문제