-1

代码:

ALTER PROCEDURE [dbo].[SP_LMS_dealerorusercreation_IUDS]
@dealrid bigint,
@rid bigint,
@stateid bigint,
@regonid bigint,
@Locid bigint,
@pid varchar(MAX),
@address varchar(max),
@dealrname varchar(25),
@landno bigint,
@mobno bigint,
@altcontno bigint,
@email varchar(35),
@desig varchar(25),
@reporting varchar(30),
@status int,
@action varchar(10),
@CompanyId Uniqueidentifier

AS
DECLARE @TranStatus VARCHAR(5)
 BEGIN TRY
    BEGIN TRANSACTION
      IF(@action='Insert')
         BEGIN
          INSERT INTO LMS_dealerorusercreation(
rid,
stateid,
regonid,
Locid,
addres,
dealrname,
landno,
mobno,
altcontno,
email,
desig,
reporting,
status,
CompanyId
)
VALUES(
@rid,
@stateid,
@regonid,
@Locid,
@address,
@dealrname,
@landno,
@mobno,
@altcontno,
@email,
@desig,
@reporting,
@status,
@CompanyId
)
SELECT @dealrid = dealrid FROM LMS_dealerorusercreation WHERE mobno = @mobno AND email = @email
EXEC [dbo].[SP_LMS_SetDealerProductMapping]
@dealerId = @dealrid,
@prodid = @pid
SET @TranStatus='TRUE';
END       

IF(@action='Update')
     BEGIN
    UPDATE LMS_dealerorusercreation set rid= @rid,
    stateid=@stateid,
    regonid=@regonid,
    Locid=@Locid,
    addres=@address,
    dealrname=@dealrname,
    landno=@landno,
    mobno=@mobno,
    altcontno=@altcontno,
    email=@email,
    desig=@desig,
    reporting=@reporting,
    status=@status
    WHERE dealrid=@dealrid

SET @TranStatus='TRUE';       
    END              
    IF(@action='Delete')
    BEGIN
    DELETE FROM LMS_dealerorusercreation WHERE dealrid=@dealrid
    SET @TranStatus='TRUE';
    END
    COMMIT TRANSACTION
    END TRY
    BEGIN CATCH
    ROLLBACK TRANSACTION
    DECLARE @AI VARCHAR(MAX)
    DECLARE @EM VARCHAR(MAX);
    SET @AI = 'Not Provided'
    SET @EM = ERROR_MESSAGE();
    EXEC USP_SetException 
    @ExceptionDetail = @EM,
    @AdditionalInfo = @AI
    SET @TranStatus='FALSE';
    END CATCH
    SELECT @TranStatus;

我得到的错误是

无法将值 NULL 插入列“dealrid”、表“DB_LMS.dbo.LMS_dealerorusercreation”;列不允许空值。插入失败。

4

3 回答 3

2

你需要做两件事之一,要么......

  • 确保您为该列传递一个非空值,或者;
  • 如果这是字段的所需属性,请确保您的列接受空值。
于 2013-09-23T10:10:00.027 回答
0

如错误消息所述,它是juat。

您正在尝试对已创建不为 null 的 dealrid 的表执行插入操作。如果您查看您的插入语句,您并没有选择并将值传递给它。

于 2013-09-23T10:47:07.897 回答
0

我在代码中看到的错误。

在插入表 LMS_dealerorusercreation 时,您从未选择 dealrid 列。请选择相同的。

INSERT INTO LMS_dealerorusercreation(
rid,
stateid,
regonid,
Locid,
addres,
dealrname,
landno,
mobno,
altcontno,
email,
desig,
reporting,
status,
CompanyId,
dealrid
)
VALUES(
@rid,
@stateid,
@regonid,
@Locid,
@address,
@dealrname,
@landno,
@mobno,
@altcontno,
@email,
@desig,
@reporting,
@status,
@CompanyId,
@dealrid
)
于 2013-09-23T10:13:47.097 回答