Click here to Skip to main content
15,914,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here I have taken Gridview in the design by using the Gridview task add new column I have generated delete,update,insert buttons by using the DataSource.

I have written command for delete,update,insert as -
C#
DeleteCommand="DELETE FROM Empdetails WHERE (Empname =raghu)";

And
C#
UpdateCommand="UPDATE Empdetails SET Empid = 1865201, Empname = 'Reddy' WHERE (Empid = 1865200)" 

By doing this it is deleting,updating only particular Empid, but I need code for deleting all the records,and updating all the records where we click the update any button in the row of Gridview.

The code which I need is only for in Gridview delete,update ,insert buttons.
For example here - Gridview in this

empname|empid|city|
raghu |18652|hyd| Delete(button)|Update(button)|insert(button)
ram |1547 |hyd|Delete(button)|Update(button)|insert(button)

Like I have records and delete,update,insert buttons.

Here I need code for only clicking the update in every row it should update, similarly delete ,insert buttons also.
Posted
Updated 15-Nov-11 1:16am
v2

there is mistake in the commands you have created, kindly create parameterised commands for your operations. follow the link for more guidance over the topic.

http://csharpdotnetfreak.blogspot.com/2009/06/gridview-objectdatasource-insert-update.html[^]

http://msdn.microsoft.com/en-us/library/ms972948.aspx[^]

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.updatecommand.aspx[^]


mark as answer if solves your problem, it motivates :)
 
Share this answer
 
Firstly deleting on the basis of name is wrong. You must have a field holding unique value. As all the records with the name "raghu" will be deleted, better use Empid

Secondly your query is wrong, it should be like this
DeleteCommand="DELETE FROM Empdetails WHERE Empid=1011";

or for what you are writing
DeleteCommand="DELETE FROM Empdetails WHERE Empname ='raghu'";
 
Share this answer
 
Comments
Raghu16 16-Nov-11 1:25am    
here i need to delete the record where i Click delete button for example if i click delete button in this row raghu |18652|hyd| Delete(button)|Update(button)|insert(button) i should delete this record and again if i click delete button in this row ram |1547 |hyd|Delete(button)|Update(button)|insert(button) delete this record
Anuja Pawar Indore 16-Nov-11 2:02am    
But Raghu in database a query will be fired against name, where the name matches that all records will be deleted, may be one row or more. I hope u undrestand what i m trying to say.
divyanivas 19-Jan-12 1:13am    
How to insert the record in Gridview for outside Button

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