如何将选择性值发送到存储过程中如果我对表中的几个任务使用相同的过程? [英] How to send selective values into stored procedue inh case I am using the same procedure for several tasks in a table ?

查看:91
本文介绍了如何将选择性值发送到存储过程中如果我对表中的几个任务使用相同的过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用单个过程说'sp_emp',默认值已经设置为null。所有crud操作都在这个单独的过程中执行。

使用C#Linq,我试图调用过程具有有限的值(例如,插入时的值的值不同,更新时的值不同)。但是我收到错误没有给出对应于字段的参数......

请帮助我如何发送差异号码。争论?



我的尝试:



我已分配对于我不想设置值的所有参数的DBNUll.value

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

推荐答案

该错误表示您缺少参数。

您使用的是实体框架吗?可能听起来像是因为你正在使用Linq?

如果你想使用单个存储过程,就像典型的spUpsertX组合插入和更新一样,你应该让sql服务器处理你的新数据是插入或更新,因为它只知道其他人是否同时更新同一个东西,这可能会改变操作的性质。这将使你需要传递一个null参数完全消失。



无论如何,我的问题所在,你不能将null或dbnull.value设置为一个过程参数本身,你必须通过在其值中指定一个值为dbnull.value的新建对象参数来设置它...赞美地说这有点笨重
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


这篇关于如何将选择性值发送到存储过程中如果我对表中的几个任务使用相同的过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆