Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL-Server Visual-Studio , +
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:
 
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 14-Aug-12 3:46am
Edited 15-Aug-12 8:43am
v7
Comments
Wes Aday at 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 at 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().
Wes Aday at 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 at 14-Aug-12 10:11am
   
I did post it to my question. Hope you can help me please.
Christian Amado at 14-Aug-12 11:24am
   
ASP.NET, Winforms, WPF, Silverlight?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

May be you can investigate about RowEditEnded event.
 
Hope it helps.
  Permalink  
Comments
Pooya F.A at 14-Aug-12 11:21am
   
Can you introduce more please.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 446
1 OriginalGriff 325
2 Yogesh Kumar Tyagi 304
3 Maciej Los 235
4 Prakriti Goyal 200
0 OriginalGriff 6,417
1 Sergey Alexandrovich Kryukov 5,344
2 Maciej Los 3,434
3 Peter Leow 3,259
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 15 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100