Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
I have a datagridview filled with a table of my database in my winforms Application.

Then I want to save datagridview to my database when I make changes to datagridview. I'm using sql Database.

Here is my code:

C#
DataTable allData = new DataTable();
SqlCommand cmd = new SqlCommand("Select * from contactTable", Connection);
cmd.CommandType = CommandType.StoredProcedure;
Connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(allData);
Connection.Close();
contactTableTableAdapter.Update(allData);


But nothing happens with this code.

At last I used insert statrements to enter the dataGridView to my database.
Posted
Updated 15-Aug-12 8:43am
v7
Comments
[no name] 14-Aug-12 9:56am    
"I searched a lot but nothing helped me"... in other words, you did not try very hard. There are tons of examples on the web and even here on CP doing this very thing. This question is asked every other day. And you could not find anything? What have you tried? What errors do you get? Where is the code that demonstrates any kind of a problem?
Pooya F.A 14-Aug-12 10:00am    
well let me introduce you. I may use TableAdapter and DataTable but nothing happens at all. Another way is updating TableAdapter by newRow().
[no name] 14-Aug-12 10:09am    
So you post code that does not do anything and has nothing to do with your question?
Pooya F.A 14-Aug-12 10:11am    
I did post it to my question. Hope you can help me please.
Christian Amado 14-Aug-12 11:24am    
ASP.NET, Winforms, WPF, Silverlight?

Could u explain a little More and what u want to achive and paste u r whole grid design and u r procedure and the out put var
 
Share this answer
 
May be you can investigate about RowEditEnded event.

Hope it helps.
 
Share this answer
 
Comments
Pooya F.A 14-Aug-12 11:21am    
Can you introduce more please.

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