0

I want to update a particular record in a Table. If that table contains other additional columns, how can i write the SP or EF code to update the record based on record ID ?

TIA

jsanalytics
  • 13,058
  • 4
  • 22
  • 43
Ranjeeth V
  • 11
  • 1
  • You mean the columns could be 100 or less? depends on the situation? – Ilyes Nov 15 '17 at 21:52
  • 1
    I would urge you to read this question and ask yourself if you think you would be able to answer this based solely on what you posted. I understand that English is not your native tongue but there are no details posted here at all. Just a vague request. – Sean Lange Nov 15 '17 at 21:53
  • Yes @sami , may be it 100 + or 1000+ just imagine – Ranjeeth V Nov 15 '17 at 21:54
  • If you have a table with 1,000 columns you are doing it wrong. That is way beyond anything even close to reasonable for a well designed table. – Sean Lange Nov 15 '17 at 21:55
  • I am confused.. You should know how many columns you have.. – Vanity Slug - codidact.com Nov 15 '17 at 21:55
  • @RanjeethV Are you asking what is the best? or something else? please your question is not clear. – Ilyes Nov 15 '17 at 22:00
  • Start by trying to explain what issue you are facing. Are you trying to minimize the amount of code or something? If you have 100 columns in your table and you want to write an update procedure you will need 100 parameters. But I am guessing as to what you are struggling with. – Sean Lange Nov 15 '17 at 22:01
  • "So is there any process in SP or Entity to Update Record based on ID" [here is SP version](https://stackoverflow.com/questions/2909118/update-a-single-row-with-t-sql#answer-2909140) and [EF version](https://stackoverflow.com/questions/30094755/entity-framework-update-record-by-id-in-c-sharp#answer-30094932). If you want to pass many parameters to SP you can [use table valued parameters](https://stackoverflow.com/questions/5595353/how-to-pass-table-value-parameters-to-stored-procedure-from-net-code#answer-10779567). Is this is what you are looking for? – Vanity Slug - codidact.com Nov 15 '17 at 22:02
  • "if that table contains more number of columns" more then *what*? – Vanity Slug - codidact.com Nov 15 '17 at 22:07
  • @sean-lange, Yes i am trying to reduce the code. – Ranjeeth V Nov 15 '17 at 22:09
  • @alex-l, Ex: Col 1 | Col 2 | Col 3 | Col 4 | Col 5 | . . . . . . . . . . .| Col100 – Ranjeeth V Nov 15 '17 at 22:12
  • So you want to do something like dynamically decide which parameters to pass? There really isn't a shortcut here. You need to define all the parameters. I will reiterate that if you have tables with even 100 columns you need to fix your design, not find clever ways of writing code that avoids fixing the problem. A properly normalized table probably should never exceed more than 30-40 columns. There are of course exceptions and most tables wouldn't be even that wide. But seriously, how can you not know the columns??? – Sean Lange Nov 15 '17 at 22:12
  • 2
    I don't post this very often but this really seems like an appropriate time. http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx – Sean Lange Nov 15 '17 at 22:13

0 Answers0