WebService (love.net original) for sharing data among complete Web sites
Source: Internet
Author: User
web| Data | Original I remember as if a net friend had asked about how to share database resources between several sites
I tested it on two computers. My code is like this to provide you with reference
There is a datasheet in the database server of site a Noteboard
Contains field ID (number), title (title), notername (message person name), Notetime (Message time)
How can I get site B to get a record of this datasheet?
Define a WebService file to access the a station database in a 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;
}
}
///////////////////////////////////////////////////////////////////////////////
Let's say this webservice in Http://www.a.com/MyViewDBService.asmx.
You can use it as a guest-side in Site B
Wsdl/l:cs/n:dbservice/out:viewdbserviceclient.cs Http://www.w.com/MyViewDBService.asmx
Generating Client Files ViewDBServiceClient.cs
Compiling DLLs with Csc/t:library/out:viewdbserviceclient.dll ViewDBServiceClient.cs
Using System;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Data;
Using System.Data.OleDb;
Using Dbservice; Introducing the name space of the client file
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
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.