Ver Mensaje Individual
  #14 (permalink)  
Antiguo 25/08/2010, 08:15
sanmon
 
Fecha de Ingreso: agosto-2010
Mensajes: 6
Antigüedad: 13 años, 8 meses
Puntos: 0
Respuesta: llenar dataSet con Store Procedure

Cita:
Iniciado por Dradi7 Ver Mensaje
Puedes Usar Tambien de Esta Forma

public DataTable MostrarConsulta(int Mes,int Anyo)
{
SqlDataAdapter Adp = new SqlDataAdapter(); // Variable q me Tomara Los Datos
SqlParameter Par = new SqlParameter(); // Variable para la Recepcion de Datos
DataSet Datos = new DataSet(); // Creando un DataSet
try
{
Adp.SelectCommand = new SqlCommand(); // Creando una Instancia de SqlCommand
Adp.SelectCommand.Connection = Con; // Indicale tu variable de conexion ojo debes estar conectado a la Base de Datos Primero
Adp.SelectCommand.CommandText = "NOM_PROC"; // Indicamos el nombre del Proc Alm.
Adp.SelectCommand.CommandType = CommandType.StoredProcedure; // Le Decimos q es de Tipo Procedure
Par = Adp.SelectCommand.Parameters.Add("@Mes", SqlDbType.Int, 4); // Creando parametro
Par.Value = 4; // aqui le puedes cambiar por una variable
Par = Adp.SelectCommand.Parameters.Add("@Anyo", SqlDbType.Int, 4);// Creando parametro
Par.Value = 2009; // aqui le puedes cambiar por una variable
Adp.Fill(Datos, "x"); // Ejecutando y Recibiendo la consulta devuelta
}
catch(Exception e){MessageBox.show(null,e.Message,"Aviso");}
return Datos.Tables["x"];
}


Hola tengo un problema, tengo algo parecido a lo que mencionas(llenar un dataset con SP), al hacer click en el dropdown si me manda Informacion a mis textbox., pero cuando cambio de Item en el mismo Dropdown no me manda la Informacion a los textbox correspondientes al segundo Item Seleccionado. anexo mi codigo, esperando me puedas ayudar. Gracias
************************************************** **********
Public Function GetDetailCITEM(ByVal CTHWRK As Integer, ByVal CITEM As String) As System.Data.DataTable


Dim Param As New SqlParameter
Dim ds As New DataSet
Dim da As SqlDataAdapter = New SqlDataAdapter("spGetCITEM", admmetrics)

da.SelectCommand.CommandType = CommandType.StoredProcedure

Param = da.SelectCommand.Parameters.Add("@CTHWRK", SqlDbType.Int)
Param.Value = CTHWRK

Param = da.SelectCommand.Parameters.Add("@CITEM", SqlDbType.NVarChar)
Param.Value = CITEM

da.Fill(ds, "tblMOEEITMSTF")
GetDetailCITEM = ds.Tables("tblMOEEITMSTF")

End Function
************************************************** **********
Private Sub ddlProductCode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlProductCode.SelectedIndexChanged
Dim DetailFields As MyDataDBConn = New MyDataDBConn

If ddlProductCode.SelectedIndex > 0 Then

Dim dt As DataTable = DetailFields.GetDetailCITEM(ddlProductCode.Selecte dValue, ddlProductCode.SelectedItem.Text)

For Each MiDataRow As DataRow In dt.Rows


Me.TxtCALIAS.Text = MiDataRow(2).ToString
Me.TxtCBUSSN.Text = MiDataRow(3).ToString
Me.TxtCFREE1.Text = MiDataRow(4).ToString
Me.TxtCFREE2.Text = MiDataRow(5).ToString

Next
End If
************************************************** *****
y como referencia este es el Query de mi Stored Procedure:

ALTER PROCEDURE [dbo].[spGetCITEM]
@CTHWRK Int,
@CITEM nvarchar(50)
AS
SELECT A.CTHWRK, A.CITEM, A.CALIAS, A.CBUSSN,
A.CFREE1, A.CFREE2
FROM tblMOEEITMSTF A
INNER JOIN tblCTHWRK B ON B.CTHWRK = A.CTHWRK
WHERE A.CTHWRK = @CTHWRK and A.CITEM = @CITEM