Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i have 3 web pages. admin,student and teacher. i have used grid view on each of this page.my table is having a column as 'status'.which is having default value 0. I want to update this value to 1 when i click on delete in gridview. I have written following code. But it is not working.pls help.

this is .aspx file code-
C#
" SelectCommand="SELECT * FROM [login] WHERE ([username] = @username)"
 DeleteCommand="UPDATE [login] SET [status]= 1 WHERE [id]=@id" 
InsertCommand="INSERT INTO [login] ([name], [midname], [surname], [username], [password], [contact], [dob], [email], [address], [occupation], [ltype]) VALUES (@name, @midname, @surname, @username, @password, @contact, @dob, @email, @address, @occupation, @ltype)
" UpdateCommand="UPDATE [login] SET [name] = @name, [midname] = @midname, [surname] = @surname, [username] = @username, [password] = @password, [contact] = @contact, [dob] = @dob, [email] = @email, [address] = @address, [occupation] = @occupation, [ltype] = @ltype WHERE [Id] = @Id">

and this is my code behind-
C#
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) 
{ 
SqlConnection con = new SqlConnection("Data Source=SNEHAL-PC\SNEHAL1;Initial Catalog=TEMPRUJU;Integrated Security=True");
 SqlCommand cmd; SqlDataReader dr;
 con.Open();
 GridViewRow row = GridView1.Rows[e.RowIndex];
 cmd=new SqlCommand("Update login set status=1 where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'",con); 
dr = cmd.ExecuteReader(); 
}
Posted
Updated 10-Feb-14 17:18pm
v3

1 solution

problem is here : dr = cmd.ExecuteReader();
use this int result = cmd.ExecuteNonQuery();

try this...


link1
 
Share this answer
 
Comments
Member 10523130 11-Feb-14 0:35am    
thanx a lot.It worked.. :)
i was trying for so long.
OPees 11-Feb-14 0:52am    
:)

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