using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.ComponentModel;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.Configuration;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public string ShowNameAndLastName(string name, string lastname)
{
string name_str = name;
string lastname_str = lastname;
return string.Format("สวัสดีครับคุณ" + name_str + " " + lastname_str + "เป็นอย่างไรบ้าง");
}
[WebMethod]
public string ConnectDB()
{
string connection13 = ConfigurationManager.ConnectionStrings["sql"].ConnectionString;
SqlConnection ceConn = new SqlConnection(connection13);
SqlCommand ceCmd = ceConn.CreateCommand();
ceCmd.CommandType = CommandType.Text;
ceCmd.CommandText = "select*from customer ";
System.Data.DataSet _Ds1 = new System.Data.DataSet();
SqlDataAdapter _npgAdap = new SqlDataAdapter(ceCmd);
_npgAdap.Fill(_Ds1, "moo");
return _Ds1;
}
}
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), WebService, C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.ComponentModel;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.Configuration;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public string ShowNameAndLastName(string name, string lastname)
{
string name_str = name;
string lastname_str = lastname;
return string.Format("สวัสดีครับคุณ" + name_str + " " + lastname_str + "เป็นอย่างไรบ้าง");
}
[WebMethod]
public DataSet ConnectDB()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source= Lincon-PC ;DataBase=Test;Integrated Security=SSPI";
string cmd = "SELECT customer.name, customer.surname, Departments.department FROM customer inner join Departments on customer.id_de = Departments.id_de";
SqlDataAdapter da = new SqlDataAdapter(cmd, con);
DataSet ds = new DataSet();
da.Fill(ds, "ohm");
return ds;
}
}