简体   繁体   English

尽管命令正确,但表未更新

[英]Table not updated despite command being correct

I use a stored procedure for inserting, updating and deleting records, and I use LINQ for executing or calling the procedures.我使用存储过程来插入、更新和删除记录,并使用 LINQ 来执行或调用这些过程。 After clicking on submit button, the update procedure has been executed but there is no change in the table.单击提交按钮后,更新过程已执行,但表中没有任何变化。 If I pass a value like "Jack" instead of fname_txt,text.如果我传递一个像“Jack”这样的值而不是 fname_txt,text。 it works and is updated?它有效并已更新? I don't know what's the different between a textbox object and a value in a quotation mark:!我不知道文本框 object 和引号中的值有什么区别:! Here is the code:这是代码:

    protected void submit_Click(object sender, EventArgs e)
    {

        try
        {
            ZobLinqDataContext db = new ZobLinqDataContext();
            string pasword = CryptorEngine.Encrypt(pass_txt.Text, true);
            long uid = Convert.ToInt64(Request["uid"]);
            db.pUpZDBUser(uid,
                uname_txt.Text,
                pasword,
                fname_txt.Text.Trim(),
                lname_txt.Text.Trim(),
                modir.Checked,
                voting.Checked,
                Convert.ToInt32(Zarib_txt.Text),
                false
                );
            db.SubmitChanges();
            Response.Write(uname_txt);
        }
        finally
        {
            Session["sub"] = "1";
        }

    }

this is the update proc:这是更新过程:

    USE [ZOBDB]
GO
/****** Object:  StoredProcedure [dbo].[pUpZDBUser]    Script Date: 04/11/2012 15:17:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[pUpZDBUser] 
    @UID bigint,
    @Uname  nvarchar(100),
    @Pass   nvarchar(100),
    @fname  nvarchar(50),
    @lname  nvarchar(50),
    @KU bit,
    @KV bit,
    @ZribV  int,
    @del bit
As
BEGIN TRANSACTION UpUser    
    Set NOCOUNT ON

    UPDATE Users SET 
        Uname=@Uname, 
        Pass=@Pass, 
        fname=@fname, 
        lname=@lname, 
        KU=@KU, 
        KV=@KV, 
        ZribV=@ZribV,
        del=@del
    where (UID=@UID)

    --RollBack if Err
    IF @@ERROR != 0 and @@ROWCOUNT != 1
    BEGIN
        declare @msg nvarchar(30)
        set @msg = ' error '+@Uname
        ROLLBACK
        RAISERROR(@msg,16,1)
        RETURN
    END
COMMIT TRANSACTION UpUser
RETURN

I think you'll have more luck if you change the SPROC to我认为如果将 SPROC 更改为

--RollBack if Err     
IF @@ERROR != 0 **OR** @@ROWCOUNT != 1 

This way you should get the error being raised and you can see what the issue is.这样你应该得到被引发的错误,你可以看到问题是什么。 Possibly the UID doesn't exist?可能 UID 不存在?

Best guess is that your proc is throwing an exception that you're not catching, perhaps because there's a length constraint on the column, and that your fname_txt.Text.Trim() value is zero length, and "Jack" of course is not.最好的猜测是你的 proc 抛出一个你没有捕获的异常,可能是因为列上有长度限制,并且你的fname_txt.Text.Trim()值是零长度,而“Jack”当然不是.

Add a catch block to your code to prover there is nothing untoward happening in your proc.在您的代码中添加一个 catch 块,以证明您的 proc 中没有发生任何异常情况。 Also more detail in your question would be helpful.您的问题中的更多详细信息也会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM