2012-04-11 2 views
3

문제는 내 webservice에서 내 dataGridView의 데이터를 가져 오는 중입니다. webservice에서 getList 메서드를 호출하면 올바른 XML 코드가 생성됩니다. 이 내 코드입니다 : 웹 서비스 :dataGridView로 데이터 가져 오기

[WebMethod] 
    public DataSet getList() 
    { 
     SqlConnection connection = new SqlConnection(); 
     connection.ConnectionString = "server=localhost;" + 
            "Trusted_Connection=yes;" + 
            "database=oving1; " + 
            "connection timeout=30"; 
     string select = "select * from Person"; 
     SqlDataAdapter da = new SqlDataAdapter(select, connection); 
     DataSet ds = new DataSet(); 

     da.Fill(ds, "Person"); 
     return (ds); 
    } 

형태 :

private void button1_Click(object sender, EventArgs e) 
    { 

     Service1 webService = new Service1(); 
     DataSet ds = webService.getList(); 
     dataGridView1.DataSource = ds; 


    } 
+0

ds를 데이터 테이블에 채우고이 테이블을 그리드보기에 연결하십시오. – Milee

+0

'ds'는 예상대로 채워 집니까? 중단 점을 사용하십시오. – SkonJeet

+2

시도해보십시오 dataGridView1.DataSource = ds.Tables [0], 또한 디자인에서 dataGridView1에 대해 false로 설정 한 자동 생성 된 열을 가지고 있지 않은지 확인하십시오 – Habib

답변

3

당신은 더 나은이 Avoiding DataSet in Web services

한 가지 더 시도 웹 서비스 Consuming a DataSet from an XML Web Service

을 통해 데이터 세트를 직렬화하기 위해 확인 그리드가 아닌 데이터 집합으로 데이터 테이블 전달 :

dataGridView1.DataSource = ds.Tables[0]; 
+1

@stianboe 또한 정답 인 – Ravia

+0

@Ravia, stianboe가 13 점을 받았습니다. 그는 투표 할 수 있도록 2 포인트가 더 필요합니다.) –

+0

@stianboe 이제 투표하실 수 있습니다. – Ravia