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

问题描述

大家好,
请帮我...,
单击链接按钮删除后,我想从表中删除第一行记录.
表行记录如下:
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........

推荐答案

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



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


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

09-12 01:14