[英]Converting ArrayOfStrings to string array
I have searched for a long time and tried different ways to solve this problem without any success. 我已经搜索了很长时间,并尝试了不同的方法来解决此问题,但没有成功。
My current program is as follows: 我当前的程序如下:
I receive a string array in the DAL that I try to send through the web service to my Controller
in the windows form program. 我在DAL中收到一个字符串数组,该数组试图通过Web服务发送到Windows窗体程序中的
Controller
。 But receive the error: 但是收到错误:
Cannot implicity convert type 'WindowsFormApplication.ServiceReference1.ArrayOfString' to 'System.Collections.Generic.List<string[]>'
无法将类型'WindowsFormApplication.ServiceReference1.ArrayOfString'隐式转换为'System.Collections.Generic.List <string []>'
Controller in form: 控制器形式:
public List<string[]> GetAllEmployee()
{
return client.GetAllEmployee();
}
Webservice: 网络服务:
public List<string[]> GetAllEmployee()
{
return cont.GetAllEmployee();
}
DAL: DAL:
public List<string[]> GetAllEmployee()
{
GetConnection();
con.Open();
stmt = con.CreateCommand();
stmt.CommandText = "SELECT [No_],[First Name],[Last Name],[Initials],[Job Title],[E-Mail] FROM [CRONUS Sverige AB$Employee]";
OdbcDataReader reader = stmt.ExecuteReader();
List<string[]> allEmployee = new List<string[]>();
String[] cols = new string[5];
for (int i = 0; i < cols.Length; ++i)
{
cols[i] = reader.GetName(i);
}
allEmployee.Add(cols);
while (reader.Read())
{
string[] s = new string[cols.Length];
for (int i = 0; i < s.Length; ++i)
{
s[i] = reader.GetValue(i).ToString();
}
allEmployee.Add(s);
}
con.Close();
return allEmployee;
}
Controller: 控制器:
public List<string[]> GetAllEmployee()
{
return dal.GetAllEmployee();
}
client: 客户:
ServiceReference1.WebService1SoapClient client = new ServiceReference1.WebService1SoapClient();
您的服务返回WindowsFormApplication.ServiceReference1.ArrayOfString
类型,需要使用ToList方法将其显式转换为List<string>
:
return dal.GetAllEmployee().ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.