asp.net - INSERT 存储过程不起作用?

标签 asp.net sql asp.net-mvc stored-procedures

我正在尝试从一个名为暂停的数据库插入到 ANimals 数据库中名为 Notification 的表中。我的存储过程是这样的:

       ALTER PROCEDURE [dbo].[spCreateNotification] 
        -- Add the parameters for the stored procedure here
        @notRecID int,
        @notName nvarchar(50),
        @notRecStatus nvarchar(1),
        @notAdded smalldatetime,
        @notByWho int
    AS
    BEGIN
        -- SET NOCOUNT ON added to prevent extra result sets from
        -- interfering with SELECT statements.
        SET NOCOUNT ON;

        -- Insert statements for procedure here
        INSERT INTO Animals.dbo.Notification 
(
NotRecID, 
NotName, 
NotRecStatus, 
NotAdded, 
NotByWho
)
values (@notRecID, @notName, @notRecStatus, @notAdded, @notByWho);
    END

空插入是补充一列,否则将不会被填充,我尝试了不同的方法,比如在表名之后也使用列的名称,然后只在值中指示我拥有的字段。我知道这不是存储过程的问题,因为我是从 sql server management studio 执行的,并且它可以引入参数。那么我想问题一定出在我调用存储过程的时候:
public void createNotification(Notification not)
        {
            try
            {
                DB.spCreateNotification(not.NotRecID, not.NotName, not.NotRecStatus,
                                        (DateTime)not.NotAdded, (int)not.NotByWho);

            }
            catch
            {
                return;
            }
        }

我在这里调用该方法:
public void createNotifications(IList<TemporalNotification> notifications)
        {

            foreach (var TNot in notifications)
            {
                var ts = RepositoryService._suspension.getTemporalSuspensionForNotificationID(TNot.TNotRecID);
                Notification notification = new Notification();
                if (ts.Count != 0)
                {
                    notification.NotName = TNot.TNotName;
                    notification.NotRecID = TNot.TNotRecID;
                    notification.NotRecStatus = TNot.TNotRecStatus;
                    notification.NotAdded = TNot.TNotAdded;
                    notification.NotByWho = TNot.TNotByWho;

                    if (TNot.TNotToReplace != 0)
                    {
                        var suspensions = RepositoryService._suspension.getSuspensionsAttached((int)TNot.TNotToReplace);
                        foreach (var sus in suspensions)
                        {
                            sus.CtsEndDate = TNot.TNotAdded;
                            sus.CtsEndNotRecID = TNot.TNotRecID;
                            DB.spModifySuspensionWhenNotificationIsReplaced((int)TNot.TNotToReplace, (int)sus.CtsEndNotRecID, (DateTime) sus.CtsEndDate);
                        }
                        DB.spReplaceNotification((int)TNot.TNotToReplace, DateTime.Now);
                        createNotification(notification);
                    }
                    else
                    {
                        createNotification(notification);
                    }
                }
            }
            deleteTemporalNotifications(notifications);
        }

它不记录数据库中的值。我一直在调试并对此感到生气,因为它在我手动执行时有效,但在我的应用程序中自动化该过程时则无效。有人看到我的代码有什么问题吗?

谢谢

编辑:添加了更多代码。改变它仍然不起作用,我的意思是,如果我执行它,该过程会起作用,所以我不知道可能是什么错误。事实上,我没有得到任何错误。这可能是在一个表中写入的问题,而该表不在您拥有存储过程的数据库中?

最佳答案

我会指定您的列名和 不要完全包含该列的 NULL。只需让 SQL Server 处理它。

INSERT INTO Animals.dbo.Notification
(
 RecID,
 [Name],
 RecStatus,
 Added,
 ByWho 
)
values (@notRecID, @notName, @notRecStatus, @notAdded, @notByWho); 

关于asp.net - INSERT 存储过程不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2857823/

相关文章:

sql - 根据条件删除重复项

asp.net-mvc - 单元测试帐户 MVC Controller 错误 - 仍在使用真正的 MembershipService

c# - 带有模型绑定(bind)的 Razor 页面 POST 多个表单

c# - 在 asp.net 中使用 System.Timers.Timer

asp.net - Devexpress 网格延迟加载

sql - 什么是 SQL Server 对 MySQL 的 unicode_ci 排序规则的模拟?

sql - 使用 PHP 显示 SQL 语句的部分结果

asp.net-mvc - 努力解决标准 Azure 网站中的 "Cold"代码问题

c# - 调试IIS随机疯狂内存使用情况

asp.net - 如何通过 SQL 查询创建 XML 文件?