Tuesday, 13 May 2014

Webservice

using System.Configuration;
using System.Data;
using System.Data.SqlClient;
public class Service : System.Web.Services.WebService {

 
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConn"].ConnectionString);
        SqlCommand cmd;


       
 
    [WebMethod]
    public void insert(string un, string pwd, string fn, string ln, string mob, string city )
    {
       
        con.Open();
        cmd = new SqlCommand("SP_Emp_Ins", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@UserName",un);
        cmd.Parameters.AddWithValue("@Password", pwd);
        cmd.Parameters.AddWithValue("@FirstName", fn);
        cmd.Parameters.AddWithValue("@LastName", ln);
        cmd.Parameters.AddWithValue("@PhoneNo", mob);
        cmd.Parameters.AddWithValue("@Location", city);
        cmd.ExecuteNonQuery();
        con.Close();
    }

    [WebMethod]
    public void update( int uid, string un, string pwd, string fn, string ln, string mob, string city)
    {

        con.Open();
        cmd = new SqlCommand("SP_Emp_Update", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Uid", uid);
        cmd.Parameters.AddWithValue("@UserName", un);
        cmd.Parameters.AddWithValue("@Password", pwd);
        cmd.Parameters.AddWithValue("@FirstName", fn);
        cmd.Parameters.AddWithValue("@LastName", ln);
        cmd.Parameters.AddWithValue("@PhoneNo", mob);
        cmd.Parameters.AddWithValue("@Location", city);
        cmd.ExecuteNonQuery();
        con.Close();
    }
    [WebMethod]
    public void delete(int id)
    {
        con.Open();
        cmd = new SqlCommand("SP_Emp_Del", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Uid", id);
        cmd.ExecuteNonQuery();
        con.Close();
    }

}

No comments:

Post a Comment