惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - DinoSaur

监测磁盘文件是否被修改程序 这两天随便写了个基类库 C#使用Jmail组件发送邮件 解决需求工程中的基本问题 如何编写用户操作手册 什么是软件需求 string.Equals(string)和==的原理 DataGrid格式 微软程序员测试题 C#中调用Windows API的要点 使用ASP.NET实现饼图 如何将一个目录里面的所有文件复制到目标目录里面。 前台对象的事件一览 剖析ASP.NET下部构造 常用的DOCUMENT.EXECCOMMAND VS.NET下web项目源代码管理 DotNet向数据库中添加图片 DataGrid应用样式文件定义动态样式 C#编码标准--编码习惯
网站间共享数据的WebService
DinoSaur · 2004-11-25 · via 博客园 - DinoSaur
 

我记得好象有一个网友问过关于怎样在几个站点间共享数据库资源我在两台电脑上试验成功了我的代码是这样的提供大家参考

在站点a的数据库服务器的数据库中有一个数据表NoteBoard包含字段ID(编号),Title(标题),NoterName(留言人名字),NoteTime(留言时间)

怎样可以让站点b获得这个数据表的记录呢。

a定义访问a站数据库的webservice文件MyViewDBService.asmx

<%@WebService Language="C#" Class="ViewDBService"%>

using System;

using System.Data;

using System.Data.OleDb;

using System.Web.Services;

public class ViewDBService : WebService

{

[WebMethod]

public DataSet ViewDB()

{

string connStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\WmjDB.mdb";

OleDbConnection conn=new OleDbConnection(connStr);

string sqls="select ID,Title,NoterName,NoteTime from NoteBoard order by id";

OleDbDataAdapter adapter=new OleDbDataAdapter();

adapter.SelectCommand=new OleDbCommand(sqls,conn);

DataSet dataSet=new DataSet();

adapter.Fill(dataSet,"NoteBoard");

conn.Close();

return dataSet;

}

}

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

假设这个webservicehttp://www.a.com/MyViewDBService.asmx

则作为客护端在站点b可以使用

wsdl /l:cs /n:DBService /out:ViewDBServiceClient.cs http://www.w.com/MyViewDBService.asmx

生成客户端文件 ViewDBServiceClient.cs

csc /t:library /out:ViewDBServiceClient.dll ViewDBServiceClient.cs 编译dll

编写客户端网页文件index.aspx

<%@page language="C#" Codebehind="index.aspx.cs" AutoEventWireup="false" Inherits="Wmj.ViewDB"%>

<html>

<head>

<title>我的留言板</title>

</head>

<body>

<form runat="server">

<center>

<asp:DataGrid id="dataGrid1" ItemStyle-BackColor="#AAAADD" AutoGenerateColumns="false"

AlternatingItemStyle-BackColor="#CCCCFF" HeaderStyle-BackColor="#000000"

HeaderStyle-HorizontalAlign="Center"

HeaderStyle-ForeColor="#FFFFFF" PagerStyle-Mode="NumericPages"

AllowPaging="true" PageSize="4" Font-Size="10pt" runat="server">

<columns>

<asp:BoundColumn HeaderText="序号" DataField="ID"/>

<asp:BoundColumn HeaderText="标题" DataField="Title"/>

<asp:BoundColumn HeaderText="留言人" DataField="NoterName"/>

<asp:BoundColumn HeaderText="留言时间" DataField="NoteTime" DataFormatString="{0:dd/MM/yyyy}"/>

</columns>

</asp:DataGrid>

<asp:Label id="label1" runat="server"/>

</center>

</form>

</body>

</html>

编写客户端文件的codebehind index.aspx.cs

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

using System;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.OleDb;

using DBService; //引入客户端文件的名字空间

namespace Wmj

{

public class ViewDB : Page

{

protected DataGrid dataGrid1;

public ViewDB()

{

this.Init+=new EventHandler(this.Page_Init);

}

public void Page_Init(object sender,EventArgs e)

{

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

this.dataGrid1.PageIndexChanged+=new

DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);

}

public void Page_Load(object sender,EventArgs e)

{

ViewDBService viewDBService=new ViewDBService();

//使用webservice

dataGrid1.DataSource=viewDBService.ViewDB().Tables["NoteBoard"].DefaultView;

if(!Page.IsPostBack)

{

dataGrid1.CurrentPageIndex=0;

dataGrid1.DataBind();

}

}

public void DataGrid1_PageIndexChanged(object sender,DataGridPageChangedEventArgs e)

{

dataGrid1.CurrentPageIndex=e.NewPageIndex;

dataGrid1.DataBind();

}

}

}