当前位置: 代码迷 >> Web Service >> 关于获取数据库值得WebService,该怎么解决
  详细解决方案

关于获取数据库值得WebService,该怎么解决

热度:245   发布时间:2016-05-02 02:58:21.0
关于获取数据库值得WebService
public   class   EmployeeService   :   System.Web.Services.WebService
        {                
                [WebMethod]
                public   Acct[]   GetEmployeeList()
                {
                        string   connectionString   =   ConfigurationManager.ConnectionStrings[ "connectionNorthwind "].ToString();
                        string   commandString   =   "select   EmployeeID,LastName,FirstName   from   Employees ";
                        SqlConnection   conn=new   SqlConnection(connectionString);                        
                        SqlDataAdapter   adapter=new   SqlDataAdapter(commandString,conn);                        
                        DataSet   ds   =   new   DataSet();
                        adapter.Fill(ds);
                        Acct[]   a   =   new   Acct[ds.Tables[0].Rows.Count];  
                        Acct   aa   =   new   Acct();                        
                        for   (int   i   =   0;   i   <   ds.Tables[0].Rows.Count;   i++)
                        {
                                aa.EmployeeID   =Convert.ToInt32(ds.Tables[0].Rows[i][0].ToString());
                                aa.LastName   =   ds.Tables[0].Rows[i][1].ToString();
                                aa.FirstName   =   ds.Tables[0].Rows[i][2].ToString();
                                a[i]   =   aa;
                        }
                        return   a;
                }
        }
        [XmlRoot( "employee ")]
        public   class   Acct
        {
                [XmlElement( "employeeID ")]
                public   int   EmployeeID;
                [XmlElement( "lastName ")]
  相关解决方案