加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

今天试了试返回dataset的webservice

发布时间:2020-12-17 02:46:53 所属栏目:安全 来源:网络整理
导读: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; namespace ?dbService ... { ???? /**/ /// ? summ

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;


namespace ?dbService

{

????
///?<summary>

????
///?Service1?的摘要说明。

????
///?</summary>

????public?class?dbService?:?System.Web.Services.WebService

????
{

????????
private?String?Connstr;


????????
public?dbService()

????????
{

????????????
//CODEGEN:?该调用是?ASP.NET?Web?服务设计器所必需的

????????????

????????????

????????????InitializeComponent();

????????????Connstr
="Provider=SQLOLEDB;Data?Source=(local);";

????????????Connstr
=Connstr+"Initial?catalog=PUBS;User?ID=sa;PassWord=sa";


????????}


????????
组件设计器生成的代码


????????
//?WEB?服务示例

????????
//?HelloWorld()?示例服务返回字符串?Hello?World

????????
//?若要生成,请取消注释下列行,然后保存并生成项目

????????
//?若要测试此?Web?服务,请按?F5?键

????????[WebMethod]


????????
public?DataSet?populate(String?SQL)

????????
{????


????????????OleDbConnection?myConnection
=new??OleDbConnection(Connstr);

????????????OleDbDataAdapter?myCommand
=new?OleDbDataAdapter(SQL,myConnection);

????????????DataSet?ds
=new?DataSet();

????????????myCommand.Fill(ds,
"vTable");

????????????
return?ds;


????????}

????????[WebMethod]

????????
public?String?RunSQL(String?vsql)

????????
{

????????????
try

????????????
{

????????????????OleDbConnection?myConnection?
=new?OleDbConnection(Connstr);

????????????????OleDbCommand?mycommand
=new?OleDbCommand(vsql,myConnection);

????????????????myConnection.Open();

????????????????mycommand.ExecuteNonQuery();

????????????????myConnection.Close();

????????????????
return("OK");

????????????}

????????????
catch?(System.Exception?e)

????????????
{

????????????????String?ret
="出现异常"+??e.ToString();

????????????????
return?ret;

????????????????

????????????}

????????}

????

????????
//????????public?string?HelloWorld()

????????
//????????{

????????
//????????????return?"Hello?World";

????????
//????????}

????}

}

?以上是webservice的代码

?

using ?System;

using ?System.Collections;

using ?System.ComponentModel;

using ?System.Data;

using ?System.Drawing;

using ?System.Web;

using ?System.Web.SessionState;

using ?System.Web.UI;

using ?System.Web.UI.WebControls;

using ?System.Web.UI.HtmlControls;


namespace ?TheClient1

{

????
///?<summary>

????
///?WebForm1?的摘要说明。

????
///?</summary>

????public?class?WebForm1?:?System.Web.UI.Page

????
{

????????
protected?System.Web.UI.WebControls.DropDownList?DropDownList1;

????????
protected?System.Web.UI.WebControls.DataGrid?DataGrid1;

????????
protected?System.Web.UI.WebControls.Label?Label1;

????????
protected?System.Web.UI.WebControls.Button?RunSql;

????????
protected?System.Web.UI.WebControls.Button?Populate;

????????
protected?System.Web.UI.WebControls.Label?message;

????????
private?localhost.dbService?mydbService=new?localhost.dbService();

????

????????
private?void?Page_Load(object?sender,?System.EventArgs?e)

????????
{

????????????
//?在此处放置用户代码以初始化页面

????????}


????????
Web?窗体设计器生成的代码


????????
private?void?Populate_Click(object?sender,?System.EventArgs?e)

????????
{

????????????DataSet?ds
=new??DataSet();

????????????String?s
=DropDownList1.SelectedItem.ToString();

????????????ds
=mydbService.populate(s);

????????????DataGrid1.DataSource
=ds;

????????????DataGrid1.DataBind();

????????}


????????
private?void?RunSql_Click(object?sender,?System.EventArgs?e)

????????
{

????????????String?s;

????????????String?ret;

????????????s
="insert?into?pub_info(pub_id,pr_info)?values('23','asdfsd')";

????????????ret
=mydbService.RunSQL(s);

????????????message.Text
=ret;

????????????DataSet?ds
=new?DataSet();

????????????s
="Select?*?from?pub_info?where?pub_id='9999'";

????????????ds
=mydbService.populate(s);

????????????DataGrid1.DataSource
=ds;

????????????DataGrid1.DataBind();


????????}


????}

}

以上是引用webservice的web页面的代码

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读