Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a gridview and data coming from datasource when i m trying to delete a row from gridview it showing "Deleting is not supported by data source 'SqlDataSource1' unless DeleteCommand is specified"
my code is
C#
string id;
        id=GridView1.DataKeys[e.RowIndex].Value.ToString();
        cmd.CommandText = "delete from room_allotment where Student_id='" + id + "'";
            conn.Open();
            int x = cmd.ExecuteNonQuery();
            conn.Close();
            if (x > 0)
            {
                DataBind();
            }
            else
            {
                lblmsg.Text = "Error..Plz try again";
            }
Posted
Comments
DamithSL 23-Nov-14 14:05pm    
in which event you have above code?
PIEBALDconsult 23-Nov-14 14:28pm    
0) Don't use concatenation to form an SQL statement; use parameters.
1) Deleting is generally a bad idea; consider setting a status instead.
2) A grid does not make for a good User Interface, particularly when editting/deleting is involved.
3) To remove a row from a Grid, you need to affect the DataTable it uses as a source. There are a few ways to do that, including setting the DefaultView.RowFilter property.
4) I hope you are not using strnigs as IDs -- integers and GUIds are better.
5) There is no reason to use ToString, just use a cast.
MJ2014 23-Nov-14 15:24pm    
Pls add full code .such that we can understand and give a solution

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