WebService.cs文件代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
/// <summary>
///WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public DataSet reader()
{
string connStr = "data source=dfsad7,1433;User ID=s;pwd=8;Initial Catalog=loDB2s";
try
{
string sqlStr = "select * from admins";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sqlStr, new SqlConnection(connStr));
da.Fill(ds);
return ds;
}
catch (Exception exp)
{
return null;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
localhost.WebService svs = new localhost.WebService();
DataSet ds = new DataSet();
ds = svs.reader();
this.GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
}