how to insert a dataset into a gridview

0

I'm trying a DataSet to a GridView . I have guided myself with some internet examples

This is part code behind and when executing it shows me the following error:

  

Fill: The SelectCommand.Connection property has not been initialized.

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();
}
    
asked by pipeRos 19.11.2017 в 03:48
source

1 answer

0

Good Pipes,

You need to indicate which connection will use SqlCommand , try this:

SqlCommand cmd = new SqlCommand("select * from carrera", con);
    
answered by 20.11.2017 в 10:00