繁体   English   中英

将ArrayOfStrings转换为字符串数组

[英]Converting ArrayOfStrings to string array

我已经搜索了很长时间,并尝试了不同的方法来解决此问题,但没有成功。

我当前的程序如下:

  • Web服务: DAL,Controller和WebService(具有Web方法)
  • Windows窗体:控制器(接收Web服务)和窗体

我在DAL中收到一个字符串数组,该数组试图通过Web服务发送到Windows窗体程序中的Controller 但是收到错误:

无法将类型'WindowsFormApplication.ServiceReference1.ArrayOfString'隐式转换为'System.Collections.Generic.List <string []>'

控制器形式:

 public List<string[]> GetAllEmployee()
 {
     return client.GetAllEmployee();
 }

网络服务:

public List<string[]> GetAllEmployee()
{
    return cont.GetAllEmployee();
}

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;
 }

控制器:

public List<string[]> GetAllEmployee()
{
    return dal.GetAllEmployee();
}

客户:

ServiceReference1.WebService1SoapClient client = new ServiceReference1.WebService1SoapClient();

您的服务返回WindowsFormApplication.ServiceReference1.ArrayOfString类型,需要使用ToList方法将其显式转换为List<string>

return dal.GetAllEmployee().ToList();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM