首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web Service >

怎么仅反回需要的记录信息

2012-01-10 
如何仅反回需要的记录信息?usingSystemusingSystem.CollectionsusingSystem.ComponentModelusingSystem

如何仅反回需要的记录信息?
using   System;
using   System.Collections;
using   System.ComponentModel;
using   System.Data;
using   System.Diagnostics;
using   System.Web;
using   System.Web.Services;
using   System.Data.OleDb;  
using   System.Data.SqlClient   ;  
namespace   HelloService
{
///   <summary>
///   Service1   的摘要说明。
///   </summary>
///  
[WebServiceAttribute(Namespace= "urn:schemas-syngress-com-soap ")]
public   class   Service1   :   System.Web.Services.WebService
{
public   Service1()
{
//CODEGEN:   该调用是   ASP.NET   Web   服务设计器所必需的
InitializeComponent();
}

#region   组件设计器生成的代码

//Web   服务设计器所必需的
private   IContainer   components   =   null;

///   <summary>
///   设计器支持所需的方法   -   不要使用代码编辑器修改
///   此方法的内容。
///   </summary>
private   void   InitializeComponent()
{

}

///   <summary>
///   清理所有正在使用的资源。
///   </summary>
protected   override   void   Dispose(   bool   disposing   )
{
if(disposing   &&   components   !=   null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion

//   WEB   服务示例
//   HelloWorld()   示例服务返回字符串   Hello   World
//   若要生成,请取消注释下列行,然后保存并生成项目
//   若要测试此   Web   服务,请按   F5   键

private   string   GetCon()
{
return     "Auto   Translate=True;User   ID=sa;Tag   with   column   collation   when   possible=False;Data   Source=.;Password=sa;Initial   Catalog=master;Use   Procedure   for   Prepare=1;Provider=SQLOLEDB.1;Persist   Security   Info=True;Workstation   ID=LP;Use   Encryption   for   Data=False;Packet   Size=4096 ";
}

[WebMethod]
public   string   HelloWorld(   string   info)
{
 
return   info;
}

[WebMethod]
public   System.Data.DataSet   GetXML(     )
{
 
OleDbConnection   OleCon   =   new   OleDbConnection(GetCon());
OleDbDataAdapter   objDataAdapter   =   new   OleDbDataAdapter( "SELECT   *   FROM   STUDENT ",OleCon);
                        DataSet   Ds=new   DataSet();    
objDataAdapter.Fill(Ds, "Tb1 ");
//OleCon.Close();  
                          return   Ds;
 
}
}
}


////////////////////////////////////////////////////////////////////
这是返回的结果:
如果仅仅返回表信息不要结构信息

<?xml   version= "1.0 "   encoding= "utf-8 "   ?>  
-   <DataSet   xmlns= "urn:schemas-syngress-com-soap ">
-   <xs:schema   id= "NewDataSet "   xmlns= " "   xmlns:xs= "http://www.w3.org/2001/XMLSchema "   xmlns:msdata= "urn:schemas-microsoft-com:xml-msdata ">
-   <xs:element   name= "NewDataSet "   msdata:IsDataSet= "true "   msdata:Locale= "zh-CN ">


-   <xs:complexType>
-   <xs:choice   maxOccurs= "unbounded ">
-   <xs:element   name= "Tb1 ">
-   <xs:complexType>
-   <xs:sequence>
    <xs:element   name= "id "   type= "xs:int "   minOccurs= "0 "   />  
    <xs:element   name= "name "   type= "xs:string "   minOccurs= "0 "   />  
    <xs:element   name= "score "   type= "xs:double "   minOccurs= "0 "   />  
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:complexType>
    </xs:element>
    </xs:schema>
-   <diffgr:diffgram   xmlns:msdata= "urn:schemas-microsoft-com:xml-msdata "   xmlns:diffgr= "urn:schemas-microsoft-com:xml-diffgram-v1 ">
-   <NewDataSet   xmlns= " ">
-   <Tb1   diffgr:id= "Tb11 "   msdata:rowOrder= "0 ">
    <id> 1 </id>  
    <name> 1 </name>  
    <score> 1 </score>  
    </Tb1>
-   <Tb1   diffgr:id= "Tb12 "   msdata:rowOrder= "1 ">
    <id> 2 </id>  
    <name> 2 </name>  
    <score> 2 </score>  
    </Tb1>
-   <Tb1   diffgr:id= "Tb13 "   msdata:rowOrder= "2 ">
    <id> 3 </id>  
    <name> 3 </name>  
    <score> 3 </score>  
    </Tb1>
-   <Tb1   diffgr:id= "Tb14 "   msdata:rowOrder= "3 ">
    <id> 4 </id>  
    <name> 4 </name>  
    <score> 4 </score>  
    </Tb1>
-   <Tb1   diffgr:id= "Tb15 "   msdata:rowOrder= "4 ">
    <id> 5 </id>  
    <name> 5 </name>  
    <score> 5 </score>  
    </Tb1>
-   <Tb1   diffgr:id= "Tb16 "   msdata:rowOrder= "5 ">
    <id> 6 </id>  
    <name> 6 </name>  
    <score> 6 </score>  
    </Tb1>
    </NewDataSet>
    </diffgr:diffgram>
    </DataSet>

///////////////////////////////////////////////////////////////////

怎么样才能返回

 
    <id> 1 </id>  
    <name> 1 </name>  
    <score> 1 </score>  
 
    <id> 2 </id>  
    <name> 2 </name>  
    <score> 2 </score>  
   
 
    <id> 3 </id>  
    <name> 3 </name>  
    <score> 3 </score>  


 
    <id> 4 </id>  
    <name> 4 </name>  
    <score> 4 </score>  
 
    <id> 5 </id>  
    <name> 5 </name>  
    <score> 5 </score>  
 
    <id> 6 </id>  
    <name> 6 </name>  
    <score> 6 </score>  
 



[解决办法]
我还有点资料:
我可以发给你,总之多互相交流吗?
QQ;30654265

热点排行