A program code writes it to a blog
Front-end
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
<HTML> WebService. asmx
<% @ WebService Language = "C #" codebehind = "~ /App_code/WebService. cs "class =" WebService "%>
WebService. CS
Using system; using system. web; using system. collections; using system. web. services; using system. web. services. protocols; using system. data; using system. data. sqlclient; using system. XML;
/// <Summary> /// Summary of WebService /// </Summary> [WebService (namespace = "http://tempuri.org/")] [webservicebinding (conformsto = wsiprofiles. basicprofile1_1)] public class WebService: system. web. services. webService {
Public WebService (){
// If the designed component is used, uncomment the following line // initializecomponent ();}
[Webmethod] Public String helloworld () {string conn = "Server = 127.0.0.1; database = temp; min pool size = 40; user id = sa; Password = sa123 "; sqlconnection myconn = new sqlconnection (conn); myconn. open (); string cmd = "select * from [user] Order by id desc"; sqldataadapter myread = new sqldataadapter (CMD, myconn); dataset myset = new dataset (); myread. fill (myset, "user"); myconn. close (); Return myset. getxml ();}}
Database Name temp
If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. [user] ') and objectproperty (ID, n' isusertable') = 1) Drop table [DBO]. [user] Go
Create Table [DBO]. [user] ([ID] [int] identity (1, 1) not null, [name] [nvarchar] (50) Collate chinese_prc_ci_as not null) on [primary] Go
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/sendling/archive/2008/10/20/3107647.aspx