2009-08-25 8 views
0

7 개의 입력란을 7 개의 텍스트 상자에 채워야합니다. 데이터는 SQL Compact DB에서 제공됩니다 ...SQL 데이터베이스에서 텍스트 상자 채우기

여기까지 내 코드가 있지만 막혀 있습니다. Form Load ...에 텍스트 상자를 채우기 위해해야 ​​할 일은 무엇입니까?

우디

private void mcContactSubmit_Load(object sender, EventArgs e) 
{ 
    // Setup our SQL connection. 
    SqlCeConnection dataSource = new SqlCeConnection(
       @"Data Source=|DataDirectory|\..\..\ContactInformation.sdf; 
       Persist Security Info=False"); 
     SqlCeDataReader myReader = null; 

    // Create our command text. 
    string sqlQuery = String.Format(@"SELECT TOP (1) FirstName, LastName, Title, 
    Department, Category, Phone, Comments FROM ContactInformation 
    ORDER BY FirstName DESC"); 

    // Open the SQL connection. 
    dataSource.Open(); 

    SqlCeCommand myCommand = new SqlCeCommand(sqlQuery, dataSource); 
    myReader = myCommand.ExecuteReader(); 
} 

답변

3

You can either use the index or the column name to get the actual data, as follows:

myReader = cmd.ExecuteReader(); 

// Run through the results 
while (myReader.Read()) 
{ 
    string fname = myReader.GetString(0); 

    // or alternatively: 

    string fname2 = myReader["FirstName"]; 

    // Either of these should work 
} 

After which, it's simple assignment to the TextBox. 그렇지 않은 경우에는 TextBox에 직접 데이터를 삽입 할 수도 있지만 대부분의 경우 유효성 검사를 수행하지 않아야합니다.

MSDN - SqlCeDataReader

+0

덕분에 친구, 쉽게 :

도움이 더 필요한 경우

은 여기 봐. – Woody

+0

좋은 물건, 다행스럽게 도와 줬다. –

+0

Doh. 나는 너무 빨리 말했다. 텍스트 상자가 채워지지 않습니다 ... 여기에 디버그 모드에서 표시되는 내용이 있습니다. 메시지 \t "기본 커서를 스크롤 할 수없는 경우 SQL Server Compact는 HasRows 속성에 대한 호출을 지원하지 않습니다." 도대체 무슨 뜻입니까?! LOL ... – Woody

관련 문제