六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

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

[摘要]我記得好象有一個網(wǎng)友問過關(guān)于怎樣在幾個站點(diǎn)間共享數(shù)據(jù)庫資源我在兩臺電腦上試驗(yàn)成功了我的代碼是這樣的提供大家參考在站點(diǎn)a的數(shù)據(jù)庫服務(wù)器的數(shù)據(jù)庫中有一個數(shù)據(jù)表NoteBoard包含字段ID(編號),Ti...
我記得好象有一個網(wǎng)友問過關(guān)于怎樣在幾個站點(diǎn)間共享數(shù)據(jù)庫資源
我在兩臺電腦上試驗(yàn)成功了我的代碼是這樣的提供大家參考
在站點(diǎn)a的數(shù)據(jù)庫服務(wù)器的數(shù)據(jù)庫中有一個數(shù)據(jù)表NoteBoard
包含字段ID(編號),Title(標(biāo)題),NoterName(留言人名字),NoteTime(留言時間)
怎樣可以讓站點(diǎn)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
則作為客護(hù)端在站點(diǎn)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="標(biāo)題" 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();
}
}
}


主站蜘蛛池模板: 夜夜夜夜夜夜夜工噜噜噜 | 特黄毛片| 日韩一级影院 | 夜夜夜夜夜夜夜工噜噜噜 | 日韩日b | 性生活一区 | 欧美一级大黄 | 青娱分类视频精品免费2 | 亚洲啪啪免费视频 | 奇米在线影视一区二区三 | 欧美一区二区激情视频 | 在线亚洲一区 | 天天爽夜夜爽天天做夜夜做 | 日韩精品在线观看视频 | 欧美一级在线免费观看 | 欧美在线一二三 | 青娱乐在线免费观看 | 日本后进式猛烈xx00动态图 | 日本高免费观看在线播放 | 亚洲成色www久久网站 | 午夜黄大色黄大片美女图片 | 四虎网站在线播放 | 天堂视频在线 | 欧美性色一级在线观看 | 亚洲第一视频在线 | 青青青久在线视频免费观看 | 日本欧美在线 | 日本卡一卡2卡3卡4精品卡网站 | 色综合久久综合欧美综合网 | 四虎影视永久免费观看网址 | 色网站免费 | 日日干夜夜拍 | 四虎免费大片aⅴ入口 | 日本视频免费看 | 日韩在线观看中文字幕 | 日韩色综合 | 亚洲高清国产一线久久 | 日韩黄色毛片 | 午夜免费网站 | 日本免费高清 | 午夜性色福利影院 |