2012-05-22 5 views
2

아래 코드는 웹 메서드입니다 (사방에서 볼 수있는 가장 일반적인 메서드입니다). 그러나 제목에서 오류가 계속 발생합니다. 나는 처음에는 .NET을 사용하기 때문에 누군가가 나를 올바른 방향으로 향하게 할 수 있다면 그렇게하십시오.'System.Data.DataSet'형식을 'string'으로 암시 적으로 변환 할 수 없습니다.

SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["mySQLconn"].ConnectionString); 

[WebMethod(Description = "Select Customers")] 
    public string GetVersionofSelectedCustomer(string versionEmail) 
    { 

     string select = "SELECT version FROM customer WHERE EMAIL = '" + versionEmail + "'"; 
     SqlDataAdapter adapter = new SqlDataAdapter(select, myConnection); 

     DataSet custDS = new DataSet();    
     //adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; 
     adapter.Fill(custDS, "Customers"); 

     return custDS; 

    } 

연결의 Web.config (로컬 접속) 및 복귀 custDS 정의되고;은 실패한 곳입니다.

+2

왜 데이터 세트를 반환하고, 고객 목록이 포함 된 JSON 응답을 반환 할 수 있습니까? –

답변

2

함수의 반환 형식이 string이고 DataSet 개체를 반환하려고합니다. 다음과 같이 시도 할 수 있습니다.

public DataSet GetVersionofSelectedCustomer(string versionEmail) 
{ 
    string select = "SELECT version FROM customer WHERE EMAIL = '" + versionEmail + "'"; 
    SqlDataAdapter adapter = new SqlDataAdapter(select, myConnection); 

    DataSet custDS = new DataSet();    
    //adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; 
    adapter.Fill(custDS, "Customers"); 

    return custDS; 

} 
+0

Uhmmm 왜 내가 그걸 보지 못했는지 모르지만 정말 고마워. 그것은 매력처럼 작동합니다. – observ

4

Dataset

public Dataset GetVersionofSelectedCustomer(string versionEmail) 
{ 
    //add your code to return dataset 
} 
1

귀하의 방법 서명이 문자열을 반환 당신이 반환 유형을 사용해야 있도록 데이터 집합을 반환하는,하지만 당신은 데이터 집합을 반환하는 - 아마도 단지를 - 그것은 당신이하고 싶은 정확히 분명하지 않다 데이터 세트를 반환하도록 서명을 변경 하시겠습니까?

관련 문제