1

I am creating web service for getting the employee details in client application. To achieve this i have followed the following steps:

employee propertyclass:

public class EmployeeProperty
{
    #region class Members.
    private string _employeeid;
    private string _employeename;   
    #endregion

    #region class property.

    public string EmployeeID
    {
      get { return _employeeid; }
      set { _employeeid = value; }
    }

    public string EmployeeName
    {
      get { return _employeename; }
      set { _employeename = value; }
    }

EmployeeDAL class:

public DataSet GetEmployeeById(EmployeeProperty employee)
{
  SqlConnection conn = new SqlConnection(connStr);    
  conn.Open();   

  // building the command
  SqlCommand oCommand = new SqlCommand("GetEmployeeById", conn);
  oCommand.CommandType = CommandType.StoredProcedure;

  // Parameters 
  SqlParameter paraemployeeId = new SqlParameter();
  paraemployeeId.ParameterName = "@employeeId";
  paraemployeeId.SqlDbType = SqlDbType.VarChar;
  paraemployeeId.Size = 15;
  paraemployeeId.Direction = ParameterDirection.Input;
  paraemployeeId.Value = employee.EmployeeID;
  oCommand.Parameters.Add(paraemployeeId);

  // Adapter and DataSet
  SqlDataAdapter oAdapter = new SqlDataAdapter();

  oAdapter.SelectCommand = oCommand;
  DataSet oDataSet = new DataSet();

  try
  {       
    oAdapter.Fill(oDataSet, "Employee");

    if (oDataSet.Tables[0].Rows.Count > 0)
    {
      employee.EmployeeID = oDataSet.Tables[0].Rows[0]["Emp_ID"].ToString();
      employee.EmployeeName = oDataSet.Tables[0].Rows[0]["Emp_Name"].ToString();         
      return oDataSet;
    }
    else
    {
      throw new ApplicationException("Business object not found.");
    }
  }
  catch (Exception oException)
  {       
    throw;
  }
  finally
  {
    conn.Close();
  }
}

WebserviceClass:

public class EmployeeWebService : System.Web.Services.WebService
{

[Webmethod]
public DataSet GetEmployeeById(EmployeeProperty employee)
{
    DataSet ds = new DataSet();
    EmployeeDAL empdal=new EmployeeDAL();
    return empdal.GetEmployeeById(employee);
}
}

From Client Application:

    webservice .EmployeeWebService empweb = new webservice .EmployeeWebService();       

    EmployeeProperty empproperty = new EmployeeProperty();         

    string empid = Txtempid.Text;

    empproperty.EmpID = empid;

    empweb.GetEmployeeById(empproperty);

    Txtempid.Text = empproperty.EmployeeID;

    Txtempname.Text = empproperty.EmployeeName;

    ....like this other values should display…..but not displaying the employee name in the text box its showing empty   value...

   What i done is correct????pls help its not working...how can i achieve it.

1 Answer 1

2

You are not using the DataSet returned by the WS.

empweb.GetEmployeeById(empproperty);

The above line returns a DataSet containing the queried data.

Sign up to request clarification or add additional context in comments.

4 Comments

Ok u mean to say ds=empweb.GetEmployeeById(empproperty); then how can populate the employeeproperty class member here..for example to display empname txtempname.text=ds.EmpName....how can i do this???
dataset.tables("tablename").rows(0).item("FieldName").tostring
txtEmpname.Tex=ds.tables[0].Rows[0]["EmployeeName"].Tostring(); its displaying but i dont want in this way empname property automatically should poup.Any help pls??
->PradeepGB: that i know, anyway thanks for replying..pls read my current comments, i am looking for some alternative way

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.