您的位置:首页 > 其它

Web服务返回Dataset对象

2009-04-20 12:52 225 查看
usingSystem;
usingSystem.Web.Configuration;
usingSystem.Web.Services;
usingSystem.Data;
usingSystem.Data.SqlClient;
usingSystem.Diagnostics;
///<summary>
///SummarydescriptionforCategoryService
///</summary>
[WebService(Namespace="http://tempuri.org/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
//ToallowthisWebServicetobecalledfromscript,usingASP.NETAJAX,uncommentthefollowingline.
//[System.Web.Script.Services.ScriptService]
publicclassCategoryService:System.Web.Services.WebService{
publicCategoryService(){
//Uncommentthefollowinglineifusingdesignedcomponents
//InitializeComponent();
}
[WebMethod]
publicDataSetGetCategoriesAsDataset()
{
try
{
using(SqlConnectionconn=newSqlConnection())
{
stringconnectionString=WebConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString;
conn.ConnectionString=connectionString;
SqlCommandcommand=newSqlCommand("select*fromProduction.ProductCategory",conn);
command.CommandType=CommandType.Text;
SqlDataAdapteradapter=newSqlDataAdapter(command);
DataSetcategories=newDataSet("Categories");
adapter.Fill(categories);
returncategories;
}
}
catch(Exceptionex)
{
EventLog.WriteEntry("Application",ex.Message);
throwex;
}
}
}

.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐