This article is a mirror article of machine translation, please click here to jump to the original article.

View: 10992|Reply: 1

[Source] About .net Execution Stored Procedure Null Automatically Becomes Default Exception Handling Method

[Copy link]
Posted on 11/9/2015 4:28:20 PM | | |
  1. ALTER PROCEDURE [dbo].[pUpdateSite]
  2.         @ID BIGINT,
  3.         @SiteName NVARCHAR(50),
  4.         @SiteDesc NVARCHAR(500),
  5.         @UpdateBy BIGINT,
  6.         @C3Confirm BIT,
  7.         @SSOUrl VARCHAR(255),
  8.         @AuthConfirm BIT,
  9.         @AuthUrl VARCHAR(255),
  10.         @Remarks NVARCHAR(500)
  11. AS
  12. BEGIN
  13.         SET NOCOUNT ON;
  14.         DECLARE @Now DATETIME
  15.         SET @Now=GETDATE()
  16.         UPDATE tbSite SET SiteName=@SiteName,SiteDesc=@SiteDesc,UpdateBy=@UpdateBy,UpdateDate=@Now,C3Confirm=@C3Confirm,SSOUrl=@SSOUrl,AuthConfirm=@AuthConfirm,AuthUrl=@AuthUrl,Remarks=@Remarks WHERE ID=@ID
  17. END
Copy code
This is my original stored procedure, where there must be 2 fields empty, either c3confirm and ssourl are empty, or authconfirm and authurl are empty,

So, I used .net to execute the stored procedure, but it was always abnormal, and I couldn't find a solution from the Internet, I saw that the SQL statement that .net finally executed was:

exec pUpdateSite @ID=20,@SiteName=N'ohoh',@SiteDesc=N'wait',@UpdateBy=1,@C3Confirm=default,@SSOUrl=default,@AuthConfirm=1,@AuthUrl=N'http://www.baidu.com',@Remarks= N'Win more and lose less'
Finally, my friend told me that the null value should be assigned a default value, so I modified it to the following code, and then it was normal.

  1. ALTER PROCEDURE [dbo].[pUpdateSite]
  2.         @ID BIGINT,
  3.         @SiteName NVARCHAR(50),
  4.         @SiteDesc NVARCHAR(500),
  5.         @UpdateBy BIGINT,
  6.         @C3Confirm BIT=NULL,
  7.         @SSOUrl VARCHAR(255)=NULL,
  8.         @AuthConfirm BIT=NULL,
  9.         @AuthUrl VARCHAR(255)=NULL,
  10.         @Remarks NVARCHAR(500)=NULL
  11. AS
  12. BEGIN
  13.         SET NOCOUNT ON;
  14.         DECLARE @Now DATETIME
  15.         SET @Now=GETDATE()
  16.         UPDATE tbSite SET SiteName=@SiteName,SiteDesc=@SiteDesc,UpdateBy=@UpdateBy,UpdateDate=@Now,C3Confirm=@C3Confirm,SSOUrl=@SSOUrl,AuthConfirm=@AuthConfirm,AuthUrl=@AuthUrl,Remarks=@Remarks WHERE ID=@ID
  17. END
Copy code






Previous:The Bootstrap modal setting does not cache data
Next:Visual Studio 2015 download address
Posted on 11/10/2015 2:31:22 PM |
There are examples of stored procedures, it's okay, I'll search on the Internet
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com