0

Estoy intentado un DataSet a un GridView. Me he guiado con algunos ejemplos de internet

Esta es parte code behind y al ejecutarlo me muestra el siguiente error:

Fill: la propiedad SelectCommand.Connection no se ha inicializado.

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack) {
        refresh();
    }
}

public void refresh() 
{
    string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["cadenaConexionAlumnos"].ConnectionString;
    SqlConnection con = new SqlConnection(connectionString);
    SqlCommand cmd = new SqlCommand("select * from carrera");
    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    DataSet dsCarrera = new DataSet();
    sda.Fill(dsCarrera);
    GVCarrera.DataSource = dsCarrera;
    GVCarrera.DataBind();
}

1 respuesta 1

0

Buenas pipeRos,

Te falta indicar que conexión va a usar el SqlCommand, prueba así:

SqlCommand cmd = new SqlCommand("select * from carrera", con);

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.