标识列值的问题 [英] problem with identity column value

查看:74
本文介绍了标识列值的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//insert order status information
db.Execute(@"
    INSERT INTO OrderStatus
    (Price, Status, PricingTime, WordsNum, DeliveryTime)
    VALUES (@0, @1, @2, @3, @4)",
    null, App.strUnVisited, null, null, null);

//I dont have AuditNum value (identity column in OrderStatus)
//insert order details
db.Execute(@"
    INSERT INTO OrderDetails
    (FileName, Lang, Description, Time, UserId, Subject, Field, AuditNum)
    VALUES (@0, @1, @2, @3, @4, @5, @6, @7)",
    ConcatFileNames, LangSelect, Description, DateTime.Now, WebSecurity.CurrentUserId, Subject, Field, AuditNum );





我有一张桌子''OrderStatus'' with标识列''AuditNum''。当我做第二次插入(在OrderDetails表中)时,会出现问题。我需要在第一次插入时自动生成的 AuditNum 值,以便将其作为(最后)参数提供给第二个插入方法。我怎么能这样做(没有并发问题)?



I have a table ''OrderStatus'' with identity column ''AuditNum''. The problem occurs when I wana do the second insert (in OrderDetails table). I need the AuditNum value that is automatically generated while the first inserting in order to give it to the second insert method as a (last) parameter. How can I do that (without concurrency problem)?

推荐答案

你好,



DatabaseClass 在WebMatrix中有一个名为 GetLastInsertId 的方法,它返回最近插入的行的标识列。使用它来检索AuditNum值,然后发出第二个插入。如需更多帮助,请参阅此链接[ ^ ]



问候,
Hello,

DatabaseClass in WebMatrix has a method named GetLastInsertId which Returns the identity column of the most recently inserted row. Use it to retrieve the AuditNum value and then issue the second insert. For more help see this link[^]

Regards,


这篇关于标识列值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆