Click here to Skip to main content
15,914,481 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a single procedure say 'sp_emp' with default values set to null already.All crud operations are being performed in this single procedure.
Using C# Linq, I am trying to call procedure with limited values (say,different no. of values in case of insertion and different no. in case of updation). But I am getting error "No argument given corresponding to field..."
Pls help how can I send the diff no. of arguments?

What I have tried:

I have assigned DBNUll.value for all those parameters already to which I do not want to set the value
Posted
Updated 21-Dec-16 0:18am
Comments
F-ES Sitecore 21-Dec-16 6:39am    
This is a bad idea, just have dedicated stored procs for CRUD actions, so one for create, one for read etc. It's done that way for a reason, and one of the reasons is the problem you're having now.
Richa Gupta 22-Dec-16 7:31am    
Seem to follow this only as no other option i am left with :(

1 solution

That error indicates that you're missing a parameter.
Are you using entity framework? could sound like that because you are using Linq?
If you want to use a single stored procedure, like the typical spUpsertX combining inserts and updates, you should let the sql server handle if your new data is an insert or an update because it alone knows if other people are updating the same thing at the same time which could change the nature of the operation. That would make your need for passing a null parameter go away alltogether.

Anyway where i thik your problem resides is that you cannot set null or dbnull.value to a procedure parameter in itself, you have to set it by assigning a newed up objectparameter with the value dbnull.value in it's value ... admitedly that's a little bit clunky
 
Share this answer
 

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