Foros del Web » Programación para mayores de 30 ;) » .NET »

Llenar un DataGrid con DataAdapter y DatSet por Código en ASP.NET

Estas en el tema de Llenar un DataGrid con DataAdapter y DatSet por Código en ASP.NET en el foro de .NET en Foros del Web. Estoy tratando de llenar un DataGrid de la siguiente forma: Código: strSQL = "Select cdCodigo, cdDescripcion from centroDistribucion" Dim SQL_Command As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL) ...
  #1 (permalink)  
Antiguo 21/05/2004, 14:52
Avatar de RsOfT  
Fecha de Ingreso: marzo-2002
Ubicación: InterNET
Mensajes: 1.121
Antigüedad: 22 años, 1 mes
Puntos: 7
Pregunta Llenar un DataGrid con DataAdapter y DatSet por Código en ASP.NET

Estoy tratando de llenar un DataGrid de la siguiente forma:

Código:
strSQL = "Select cdCodigo, cdDescripcion from centroDistribucion"
Dim SQL_Command As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL)
Dim daCentroDist As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(SQL_Command)
Dim dsCentroDist As DataSet = New DataSet("dsCentroDist")

cnn.Open()
    daCentroDist.SelectCommand.CommandText = strSQL
    daCentroDist.Fill(dsCentroDist)
    
    cobCentroDist.DataSource = dsCentroDist
    cobCentroDist.DataTextField = "cdDescripcion"
    cobCentroDist.DataValueField = "cdCodigo"
    cobCentroDist.DataBind()
cnn.Close()
La variable cnn es un objeto de tipo SqlConnection agregado en forma de diseño.

Me tira el siguiente error:
===========================
Fill: SelectCommand.Connection property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Fill: SelectCommand.Connection property has not been initialized.

Source Error:

Line 45: daCentroDist.Fill(dsCentroDist)
===========================

Qué estoy haciendo mal?
__________________
.::RsOfT::.
--El que se aferra a lo conocido, nunca conocerá lo desconocido--
--Es intentando lo imposible como se realiza lo posible--
--Es de pésimo gusto contentarse con algo mediocre cuando lo excelente está a nuestro alcance--
  #2 (permalink)  
Antiguo 21/05/2004, 15:24
Avatar de RootK
Moderador
 
Fecha de Ingreso: febrero-2002
Ubicación: México D.F
Mensajes: 8.004
Antigüedad: 22 años, 2 meses
Puntos: 50
Prueba de ésta forma:

Cita:
strSQL = "Select cdCodigo, cdDescripcion from centroDistribucion"

Dim daCentroDist As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(strSQL , cnn)
Dim dsCentroDist As DataSet = New DataSet("dsCentroDist")
daCentroDist.Fill(dsCentroDist)
cobCentroDist.DataSource = dsCentroDist
cobCentroDist.DataTextField = "cdDescripcion"
cobCentroDist.DataValueField = "cdCodigo"
cobCentroDist.DataBind()
Saludos
__________________
Nadie roba nada ya que en la vida todo se paga . . .

Exentrit - Soluciones SharePoint & Net
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas (incluyéndote)




La zona horaria es GMT -6. Ahora son las 16:58.