Tema: Web Service
Ver Mensaje Individual
  #6 (permalink)  
Antiguo 16/06/2009, 14:23
pali_wichis
 
Fecha de Ingreso: febrero-2008
Mensajes: 111
Antigüedad: 16 años, 2 meses
Puntos: 1
Respuesta: Web Service

ok...va-
el primero corresponde a la pagina default.aspx y el 2° a la clase que se encuentra en mi webservice que se llama WSRef (referencia Web)...

Código:
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        WSRef.Service objWS = new WSRef.Service();
        DataSet objData = objWS.MuestraVehiculo();

        if (objData != null)
        {
            if (objData.Tables.Count > 0)
            {
                Grilla.DataSource = objData.Tables[0].DefaultView;
                ///DefaultView: permite dejar la info como texto plano: columnas con sus valores 
                Grilla.DataBind();

            }

        }
        

    }

Código:
public class Vehiculo
{
    string _modelo = "", _color = "";
    int _idmarca = 0, _agno = 0, _precio =0; 

	public Vehiculo()
	{
		//
		// TODO: Agregar aquí la lógica del constructor
		//
	}
    SqlConnection objCon;
    SqlCommand objCom;
    SqlDataAdapter objAdapter;
    DataSet objData;

    public string Modelo
    {
        get { return _modelo; }
        set { _modelo = value; }
    }
    public string Color
    {
        get { return _color; }
        set { _color = value; }
    }
    public int Marca
    {
        get { return _idmarca; }
        set { _idmarca = value; }
    }
    public int Año
    {
        get { return _agno; }
        set { _agno = value; }
    }
    public int Precio
    {
        get { return _precio; }
        set { _precio = value; }
    }
    
    public DataSet ObtenerVehiculo()
    {
        objData = null;
        try
        {
            objCon = new SqlConnection();
            objCon.ConnectionString = "Data Source = PAULINA; Initial Catalog = Auto; Integrated Security = True";
            objCon.Open();

            if (objCon.State == ConnectionState.Open)
            {
                objCom = new SqlCommand();
                objAdapter = new SqlDataAdapter();
                objData = new DataSet();
                objCom.Connection = objCon;
                objCom.CommandType = CommandType.StoredProcedure;
                objCom.CommandText = "sp_ConsultaAuto";
                objAdapter.SelectCommand = objCom;
                objAdapter.Fill(objData);
            }
        }
        catch
        {
            objData = null;
        }
        finally
        {
            if (objCon.State == ConnectionState.Open)
            {
                objCon.Close();
                objCon = null;
                objCom = null;
            }
        }
        return objData;

    }