Click here to Skip to main content
15,887,875 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: One button submit that updates my database(insert,delete,..) without using DataAdapter Pin
Member 1038849419-Dec-13 1:35
Member 1038849419-Dec-13 1:35 
GeneralRe: One button submit that updates my database(insert,delete,..) without using DataAdapter Pin
Dave Kreskowiak19-Dec-13 2:00
mveDave Kreskowiak19-Dec-13 2:00 
GeneralRe: One button submit that updates my database(insert,delete,..) without using DataAdapter Pin
Member 1038849419-Dec-13 2:02
Member 1038849419-Dec-13 2:02 
GeneralRe: One button submit that updates my database(insert,delete,..) without using DataAdapter Pin
Dave Kreskowiak19-Dec-13 3:12
mveDave Kreskowiak19-Dec-13 3:12 
GeneralRe: One button submit that updates my database(insert,delete,..) without using DataAdapter Pin
Edward Giles19-Dec-13 22:27
Edward Giles19-Dec-13 22:27 
AnswerRe: One button submit that handles the work with the database Pin
Eddy Vluggen19-Dec-13 8:09
professionalEddy Vluggen19-Dec-13 8:09 
GeneralRe: One button submit that handles the work with the database Pin
Member 1038849419-Dec-13 8:16
Member 1038849419-Dec-13 8:16 
GeneralRe: One button submit that handles the work with the database Pin
Richard Deeming19-Dec-13 8:47
mveRichard Deeming19-Dec-13 8:47 
Well, if you want to replicate what the DataAdapter does, you'll have to:
  • Create a DbCommand and relevant parameters to delete a row;
  • Call GetChanges(DataRowState.Deleted) on the DataTable;
  • Iterate through the returned rows, assigning the relevant values to the parameters and executing the command to delete the row from the database;
  • Create a DbCommand and relevant parameters to update a row;
  • Call GetChanges(DataRowState.Modified) on the DataTable;
  • Iterate through the returned rows, assigning the relevant values to the parameters and executing the command to update the row in the database;
  • Create a DbCommand and relevant parameters to insert a new row;
  • Call GetChanges(DataRowState.Added) on the DataTable;
  • Iterate through the returned rows, assigning the relevant values to the parameters and executing the command to insert the row in the database;


If you're dealing with multiple tables, you'll need to ensure that you handle them in the correct order to make sure that you don't try to insert a child row before the related parent row.

If you want to add concurrency, you'll need to pass the original values of the relevant columns to your update and delete procedures. Use row[column, DataRowVersion.Original] to read the original value.

You'll probably want to wrap everything up in a DbTransaction to make sure the changes are atomic.

In short, it's a lot of work that you don't really need to do, as the DbDataAdapter already does it for you.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: One button submit that handles the work with the database Pin
Member 1038849419-Dec-13 9:38
Member 1038849419-Dec-13 9:38 
GeneralRe: One button submit that handles the work with the database Pin
Member 1038849420-Dec-13 7:24
Member 1038849420-Dec-13 7:24 
GeneralRe: One button submit that handles the work with the database Pin
Eddy Vluggen20-Dec-13 7:38
professionalEddy Vluggen20-Dec-13 7:38 
GeneralRe: One button submit that handles the work with the database Pin
Dave Kreskowiak19-Dec-13 9:29
mveDave Kreskowiak19-Dec-13 9:29 
Questionsyntax error while updating a record Pin
Member 1038849418-Dec-13 3:07
Member 1038849418-Dec-13 3:07 
AnswerRe: syntax error while updating a record Pin
Pete O'Hanlon18-Dec-13 3:39
mvePete O'Hanlon18-Dec-13 3:39 
GeneralRe: syntax error while updating a record Pin
Member 1038849418-Dec-13 3:57
Member 1038849418-Dec-13 3:57 
GeneralRe: syntax error while updating a record Pin
Pete O'Hanlon18-Dec-13 4:00
mvePete O'Hanlon18-Dec-13 4:00 
GeneralRe: syntax error while updating a record Pin
Member 1038849418-Dec-13 4:03
Member 1038849418-Dec-13 4:03 
GeneralRe: syntax error while updating a record Pin
Pete O'Hanlon18-Dec-13 4:10
mvePete O'Hanlon18-Dec-13 4:10 
GeneralRe: syntax error while updating a record Pin
Richard Deeming18-Dec-13 4:13
mveRichard Deeming18-Dec-13 4:13 
GeneralRe: syntax error while updating a record Pin
Member 1038849418-Dec-13 4:24
Member 1038849418-Dec-13 4:24 
GeneralRe: syntax error while updating a record Pin
Pete O'Hanlon18-Dec-13 4:38
mvePete O'Hanlon18-Dec-13 4:38 
GeneralRe: syntax error while updating a record Pin
Richard Deeming18-Dec-13 5:02
mveRichard Deeming18-Dec-13 5:02 
JokeRe: syntax error while updating a record Pin
Pete O'Hanlon18-Dec-13 5:07
mvePete O'Hanlon18-Dec-13 5:07 
GeneralRe: syntax error while updating a record Pin
Member 1038849418-Dec-13 21:22
Member 1038849418-Dec-13 21:22 
AnswerRe: syntax error while updating a record Pin
Chris Quinn18-Dec-13 4:18
Chris Quinn18-Dec-13 4:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.