下面的代码是web方法(最常见的是你可以在任何地方看到它),但我不断从标题中得到错误。我刚开始使用.NET,所以如果有人能指出我正确的方向,请这样做。
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; 是失败的地方。
答案 0 :(得分:4)
您正在返回数据集,因此您应该将返回类型用作Dataset
public Dataset GetVersionofSelectedCustomer(string versionEmail)
{
//add your code to return dataset
}
答案 1 :(得分: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;
}
答案 2 :(得分:1)
您的方法签名返回一个字符串,但是您正在返回一个DataSet - 它不清楚您想在这里做什么 - 可能只是更改签名以返回数据集?