2011-08-23 2 views
1

이미 데이터가 있다고 가정 할 수있는 DataView로 DataGridView를 채우고 싶습니다. 나는 이것을 수행하는 방법을 찾고 있었지만 모든 솔루션은 DataView 이외의 다른 데이터 구조를 포함하거나이 프로젝트에서 구현할 수없는 다른 라이브러리를 사용합니다. 처음에 DataView를 다른 것으로 변환해야하고 DataGridView를 채우는 데 사용해야합니까? 아니면 비슷한 방식으로 정보를 표시하는 DataGridView보다 사용할 수있는 뭔가가 있습니까?DataView로 DataGridView 채우기

+0

은 분명히 난 그냥 DataView의 Table 속성을 사용할 수 있습니다와 같은 것을 사용 DataGridView의 DataSource입니다. 나는 그것을 시도해보고 그것이 효과가 있다면 해결책으로 두겠다. – Boumbles

답변

1

How to: Bind a DataView Object to a Windows Forms DataGridView Control

이것은 내가 잘못 읽기이 문서가 문제를 해결하지만, 만약 그렇다면 코멘트 나는 시도하고 도움이되지 않습니다 어쩌면 모든 기본, 난 그냥 봤 "DataView를하는 datagridview.datasource"입니다

private void GetData() 
{ 
    try 
    { 
     // Initialize the DataSet. 
     dataSet = new DataSet(); 
     dataSet.Locale = CultureInfo.InvariantCulture; 

     // Create the connection string for the AdventureWorks sample database. 
     string connectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;" 
      + "Integrated Security=true;"; 

     // Create the command strings for querying the Contact table. 
     string contactSelectCommand = "SELECT ContactID, Title, FirstName, LastName, EmailAddress, Phone FROM Person.Contact"; 

     // Create the contacts data adapter. 
     contactsDataAdapter = new SqlDataAdapter(
      contactSelectCommand, 
      connectionString); 

     // Create a command builder to generate SQL update, insert, and 
     // delete commands based on the contacts select command. These are used to 
     // update the database. 
     SqlCommandBuilder contactsCommandBuilder = new SqlCommandBuilder(contactsDataAdapter); 

     // Fill the data set with the contact information. 
     contactsDataAdapter.Fill(dataSet, "Contact"); 

    } 
    catch (SqlException ex) 
    { 
     MessageBox.Show(ex.Message); 
    } 
}