Click here to Skip to main content
15,355,050 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Data source is an invalid type, it must be either an IListSource, IEnumerable or IDataSource.
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        string Sno = ((TextBox)GridView1.Rows[e.RowIndex]
        string Name = ((TextBox)GridView1.Rows[e.RowIndex]
        string Age = ((TextBox)GridView1.Rows[e.RowIndex]
        string Address = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtaddress")).Text;

        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "update Details set Sno=@Sno, Name=@Name," +
     "Age=@Age where Sno=@Sno;" +
     "select Sno,Name,Age,Address from Details";

        cmd.Parameters.Add("@Sno", SqlDbType.Int).Value = Sno;
        cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = Name;
        cmd.Parameters.Add("@Age", SqlDbType.VarChar).Value = Age;
        cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = Address;

        GridView1.EditIndex = -1;
        GridView1.DataSource = (cmd);

When I run error occurs as follows Data source is an invalid type. It must be either an IListSource, IEnumerable or IDataSource.
In this line error occurs
GridView1.DataSource = (cmd);

Please help me what is the problem form the above code I send.
Updated 30-Nov-12 0:59am
Mendor81 30-Nov-12 7:04am

Please don't double post the same question

you are assigning "cmd" to Gridview Datasource which is wrong
GridView1.DataSource = (cmd);
You have to assign datatbale to Gridview.
execute cmd and get data into datatable and assign to gridview
Hello ...

you can not assign gridview.datasource=(cmd);

you can assign dataset or datatable

GridView1.DataSource = ds;

GridView1.DataSource = dt;

depends on your fill method
You are not executing your command cmd before assigning it to grid.
1) execute cmd and save it in datatable or dataset.
2) Bind dataset/datatable to grid

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900