Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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]
                            .FindControl("txtSno")).Text;
        string Name = ((TextBox)GridView1.Rows[e.RowIndex]
                            .FindControl("txtName")).Text;
        string Age = ((TextBox)GridView1.Rows[e.RowIndex]
                            .FindControl("txtage")).Text;
        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);
        GridView1.DataBind();
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.
Posted 30-Nov-12 0:56am
Edited 30-Nov-12 0:59am
v2
Comments
Mendor81 at 30-Nov-12 7:04am
   
http://www.codeproject.com/Questions/501502/Gridviewplusupdatingpluserror
 
Please don't double post the same question
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hello ...
 

you can not assign gridview.datasource=(cmd);
 
you can assign dataset or datatable
 
GridView1.DataSource = ds;
or

GridView1.DataSource = dt;
 

 
depends on your fill method
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 428
1 Maciej Los 260
2 Sergey Alexandrovich Kryukov 220
3 DamithSL 208
4 Dave Kreskowiak 200


Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid