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?