通过在存储过程中传递空值来删除记录 [英] delete the record by passing null value in stored procedure

查看:94
本文介绍了通过在存储过程中传递空值来删除记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
请帮我...,
单击链接按钮删除后,我想从表中删除第一行记录.
表行记录如下:
UID名称MobileNo FID操作
15 Ram 8057965420 NULL删除
10 shyam 12删除

为此,我通过将数据类型值UID和FID传递给int来使用存储过程.
问题在这里,UID = 15可以,但是FID = NULL
如何在存储过程中将int FID传递为null.



在此先感谢........

Hi all,
plz help me....,
i want to delete first row record from table on click of link button delete.
Table row record likes as follow:
UID Name MobileNo FID Action
15 Ram 8057965420 NULL Delete
10 shyam 12 Delete

for this i use stored procedure by passing to int datatype values UID and FID.
problem is here UID=15 is ok, but FID=NULL
how to pass int FID as null in stored procedure.



Thanks in advance........

推荐答案


检查此
Hi ,
Check this
CREATE PROCEDURE usp_Delete
(
@UID int ,@FID  int =NULL
)
AS
BEGIN
SET NOCOUNT ON;

DELETE FROM TableName WHERE UID=@UID and  FID = @FID

END





void Delete(int uid, int? fid)
 {
     using (
       SqlConnection con =
           new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
     {
         con.Open();
         using (SqlCommand cmd = new SqlCommand("usp_Delete", con))
         {
             cmd.Parameters.AddWithValue("@UID", uid);
             cmd.Parameters.AddWithValue("@FID", fid);
             cmd.ExecuteNonQuery();
         }

     }

 }



最好的问候
M.Mitwalli



Best Regards
M.Mitwalli


尽管如此,我还是无法理解为什么您可能会想用这种方式回答您的问题,如果您需要为存储过程的任何参数传递null值,那么您可以使用DBNull.Value
I am not able to understand why you might want to do this way nevertheless to answer your question, If you need to pass the null value for any parameter of stored procedure then you can use DBNull.Value





您可以在您的存储过程中编写


Hi,


You can write in ur stored procedure


delete from xys where UID=15 and (FID=28 or FID is NULL)


这篇关于通过在存储过程中传递空值来删除记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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