标签:
1 using System; 2 using System.Web; 3 using System.Web.Services; 4 using System.Web.Services.Protocols; 5 using System.Data.OleDb; 6 using System.Data; 7 using System.IO; 8 9 10 [WebService(Namespace = "http://tempuri.org/")] 11 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 12 public class Service : System.Web.Services.WebService 13 { 14 public Service () { 15 16 //如果使用设计的组件,请取消注释以下行 17 //InitializeComponent(); 18 } 19 20 //[WebMethod] 21 //public string HelloWorld() { 22 // return "Hello World"; 23 //} 24 25 [WebMethod] 26 public DataSet strSQL() 27 { 28 OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=F:\\zjq\\webserver\\webs\\data.mdb"); 29 OleDbCommand cmd = new OleDbCommand("select * from usesr", con); 30 con.Open(); 31 OleDbDataReader sdr = cmd.ExecuteReader(); 32 // 33 DataTable table = new DataTable("table1"); 34 table.Columns.Add("uses"); 35 table.Columns.Add("pws"); 36 // 37 while (sdr.Read()) 38 { 39 table.Rows.Add(new string[2] {sdr.GetString(0),sdr.GetString(1) }); 40 } 41 // 42 DataSet dataset = new DataSet("DataSet1"); 43 dataset.Tables.Add(table); 44 return dataset; 45 } 46 47 // 48 [WebMethod] 49 public string strSQL2() 50 { 51 OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=F:\\zjq\\webserver\\webs\\data.mdb"); 52 OleDbCommand cmd = new OleDbCommand("select * from usesr", con); 53 con.Open(); 54 OleDbDataReader sdr = cmd.ExecuteReader(); 55 // 56 DataTable table = new DataTable("table1"); 57 table.Columns.Add("uses"); 58 table.Columns.Add("pws"); 59 // 60 while (sdr.Read()) 61 { 62 table.Rows.Add(new string[2] { sdr.GetString(0), sdr.GetString(1) }); 63 } 64 // 65 DataSet dataset = new DataSet("DataSet1"); 66 dataset.Tables.Add(table); 67 // 68 System.Text.StringBuilder strbuilder = new System.Text.StringBuilder(); 69 StringWriter writer = new StringWriter(strbuilder); 70 dataset.WriteXml(writer, System.Data.XmlWriteMode.IgnoreSchema); 71 72 return strbuilder.ToString(); 73 74 } 75 76 }
C#.NET 建立Web Services实例-(DataSet)
标签:
原文地址:http://www.cnblogs.com/FKdelphi/p/4633838.html