Click here to Skip to main content
15,911,848 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to delete a row from gridview in asp.net on the base of primary key.
I don't know where i am missing in my code. Please help to find out my error.

What I have tried:

C#
//that is my method which i am using
 protected void deleting() {

            conn.Open();
            string del = "Delete from Task_Assingment where [Row#] = @Row#";
            SqlCommand sq = new SqlCommand(del, conn);
            sq.ExecuteNonQuery();
            conn.Close();

        }
//in that code Row# is my column name(which is my primary key)
Posted
Updated 24-Mar-17 16:18pm
v2
Comments
[no name] 24-Mar-17 16:54pm    
Your code has nothing to do with any gridview.
Hassaan_Malik 24-Mar-17 17:11pm    
actually i have added a button (select index) in each row of gridview. The on clicking the button i am calling that method (deleting) to delete my row from the gridview. Got it?
[no name] 24-Mar-17 20:11pm    
Sure if you say so. This code STILL does not have anything to do with any gridview.
j snooze 24-Mar-17 17:07pm    
I would also say you are not actually passing in a row number anywhere or replacing the @Row# in your query with the actual row number. You need to tell your query what to replace @Row# with or it has no idea what you're talking about.
CHill60 24-Mar-17 19:53pm    
And even if you get the delete from your database working you may still need to refresh or rebind the DataGrid

1 solution

need to have initialization of row# to delete the entire row. just assign the id to given variable to make it work.
where [row#] must have to be assigned to id can use cell_row_click in Grid to select the very first id by using [e.index] method to assign the id or any other means to have flow to be created from id of dB to grid . thank you  
 
Share this answer
 

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