国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

完整的網(wǎng)站間共享數(shù)據(jù)的WebService

2024-07-21 02:21:48
字體:
供稿:網(wǎng)友
中國最大的web開發(fā)資源網(wǎng)站及技術(shù)社區(qū),
完整的網(wǎng)站間共享數(shù)據(jù)的webservice

我記得好象有一個網(wǎng)友問過關(guān)于怎樣在幾個站點間共享數(shù)據(jù)庫資源
我在兩臺電腦上試驗成功了我的代碼是這樣的提供大家參考
在站點a的數(shù)據(jù)庫服務(wù)器的數(shù)據(jù)庫中有一個數(shù)據(jù)表noteboard
包含字段id(編號),title(標題),notername(留言人名字),notetime(留言時間)
怎樣可以讓站點b獲得這個數(shù)據(jù)表的記錄呢。
在a定義訪問a站數(shù)據(jù)庫的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;
}
}
///////////////////////////////////////////////////////////////////////////////
假設(shè)這個webservice在http://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
編寫客戶端網(wǎng)頁文件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();
}
}
}



作者:love.net
來源:love.net
供稿人:江磊晶 
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 舟曲县| 滕州市| 米林县| 崇仁县| 马龙县| 大姚县| 株洲县| 吉林省| 曲阜市| 通渭县| 安溪县| 定远县| 女性| 贞丰县| 江阴市| 内江市| 福安市| 扎鲁特旗| 洛宁县| 馆陶县| 梨树县| 会同县| 明光市| 临安市| 北票市| 册亨县| 达日县| 安陆市| 安吉县| 敖汉旗| 兴安县| 兴文县| 永吉县| 东平县| 涿州市| 漳浦县| 美姑县| 密山市| 平利县| 安徽省| 曲阜市|