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


}



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


//Web 服务设计器所必需的

private IContainer components = null;



/**//// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void InitializeComponent()


...{

}



@H_589_404@/**/@H_502_406@/// <summary>

/// 清理所有正在使用的资源。

/// </summary>

protected override void dispose( bool disposing )


...{

if(disposing && components != null)


...{

components.dispose();

}

base.dispose(disposing);

}


#endregion


// 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 窗体设计器生成的代码#region Web 窗体设计器生成的代码

override protected void OnInit(EventArgs e)


...{

//

// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。

//

InitializeComponent();

base.OnInit(e);

}



/**//// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void InitializeComponent()


...{

this.Runsql.Click += new System.EventHandler(this.Runsql_Click);

this.Populate.Click += new System.EventHandler(this.Populate_Click);

this.Load += new System.EventHandler(this.Page_Load);


}

#endregion


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
页面的
代码
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。