Click here to Skip to main content
16,013,440 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have gridview in my page and it shows the datas from the database.

My question is if I update any values inside the database it must be updated in my database.

I tried many times but its not updating.
Posted
Updated 23-Feb-11 0:37am
v3
Comments
DaveAuld 23-Feb-11 6:05am    
Does it throw any errors? are you actually performing an update/commit against the datasource? What code are you using to do the update?
shanthikalai 23-Feb-11 6:28am    
con.Open();
MySqlCommand cmd = new MySqlCommand("update exam set name1=@name,ques=@ques where id = @id", con);
cmd.CommandType = CommandType.Text;
TextBox name = (TextBox)GridView1.Rows[e.RowIndex].Cells[1].FindControl("name");
TextBox ques = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].FindControl("ques");
cmd.Parameters.Add("@name", MySqlDbType.VarChar).Value = name.Text;
cmd.Parameters.Add("@ques", MySqlDbType.VarChar).Value = ques.Text;
cmd.Parameters.Add("@id", MySqlDbType.Int16).Value = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;



this is my coding...
Dalek Dave 23-Feb-11 6:38am    
Edited for Grammar and Readability.

Hope data-gridview-edit-delete-update-C-net[^]this might help you.
 
Share this answer
 
Do you mean to update the values that you have changed in the GridView back to the database? If that is what you meant then you need to create an event that will do this for you otherwise how does the program know that it should do something?

The simplest way to get you going is to drop a button on the page and create an event for it. Once you have changed data in the grid the button needs to be pressed to kick off the event. Inside the event you need to get all of the data and pass it back to the database. Since you have initiated a PostBack the page will refresh and, if you have properly bound the control, the new data should appear. As I said, that is very simplistic but should get you started - once you are comfortable with and understand this you can add sophistication to your code. Give it a try and if you get stuck ask another question.
 
Share this answer
 
Comments
Dalek Dave 23-Feb-11 6:38am    
Good Call.

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