3

I have an sql table with

ID(unique) Name status
1          A    0
2          B    0

In my code, I retrieve all data into a data table and do some coding. Based on the results, I will change the results from 0 to 1 or 2

After that, I need to update them back to sql.

My idea is to create a temp table, insert every row into that .. and then update them to the real sql table, delete the temp table.

Not very good, I know. That's why I am asking, is there any better way to do that?

Adam Wenger
  • 17,100
  • 6
  • 52
  • 63
william
  • 7,284
  • 19
  • 66
  • 106

1 Answers1

0

You can update the content of the table back working with a CommandBuilder .

Take a look at this example .

aleroot
  • 71,077
  • 30
  • 176
  • 213
  • I've heard of that, but I am not sure how to use it in my situation since mine is "update TBLSOMETHING set status= newstatus where id= idfromdatatable". can i add that query in sqldataadapter and put parameters for those 2 variables? – william Nov 12 '11 at 10:46
  • You have to load the table from database with a datadapter filling a datatable, then change the record you want to change directly in the datatable and so update the target table using command builder, take a look at the example that i've linked. – aleroot Nov 12 '11 at 10:50
  • Oh, that's how it works.. i was thinkin the wrong way.. one more question, .Update() will only replace the updated values and not replacing the whole table, rite? coz as I mentioned in my question, my ID is auto increment unique number. btw, Tkz a lot.. – william Nov 12 '11 at 11:14
  • Generally you should add code samples to your answer in the (all too common) event that links go down. – Chad Jul 03 '19 at 21:30