n层BLL插入检​​索标识

时间:2014-01-16 21:51:21

标签: c# n-tier-architecture

我在stackoverflow上问的第一个问题,所以我希望我正确地问。我找到了这个链接C# .NET4.0 TableAdapter.Update() won't insert new record

我正在尝试对此进行扩展并返回插入的记录的标识。我知道这可以做,但在C#中有一些语法问题。

BLL for insert

[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
public int InsertNewTicket(string ticket, DateTime sub_date, string sub_ADID, bool completed, DateTime? comp_Date, bool Bw, string bW_ADID, bool c_Back)
{
    ServiceDesk.SDDataTable InsertNew = new ServiceDesk.SDDataTable();
    ServiceDesk.SDRow NewTicketValues = InsertNew.NewSDRow();        
    NewTicketValues.Ticket = ticket;
    NewTicketValues.Sub_date = sub_date;
    NewTicketValues.Sub_ADID = sub_ADID;
    NewTicketValues.Completed = completed;
    if (comp_Date == null) NewTicketValues.SetComp_DateNull(); else NewTicketValues.Comp_Date = comp_Date.Value;
    NewTicketValues.BW = Bw;
    NewTicketValues.BW_ADID = bW_ADID;
    NewTicketValues.C_Back = c_Back;
    InsertNew.AddSDRow(NewTicketValues);    
    int rowsAffected = Adapter.Update(InsertNew);
    return rowsAffected;
}

这是UI的插入

 protected void Sub_Click(object sender, EventArgs e)
{
    SDBLL insernewticketadapter = new SDBLL();

    string ticket = TicketNumberBox.Text;
    DateTime sub_date = DateTime.Now;
    string sub_ADID = Server.HtmlEncode(Request.Cookies["UserInfo"]["userADID"]);
    bool completed = false;
    DateTime? comp_Date = null;
    bool Bw = false;
    string bW_ADID = null;
    bool c_Back = false;
    int newSDID;
    try
    {
        newSDID = insernewticketadapter.InsertNewTicket(ticket, sub_date, sub_ADID, completed, comp_Date, Bw, bW_ADID, c_Back);

        idofnewrecord.Text = Convert.ToString(newSDID);
    }
    catch (ArgumentException ae)
    {
        idofnewrecord.Text = ae.Message;
    }


}  

非常简单我只想在UI中返回插入的记录的ID。 数据集插入是

INSERT INTO [OKC_CALL].[SD].[SD] ([Ticket], [Sub_date], [Sub_ADID], [Completed], [Comp_Date], [BW], [BW_ADID], [C_Back]) 
VALUES (@Ticket, @Sub_date, @Sub_ADID, @Completed, @Comp_Date, @BW, @BW_ADID, @C_Back);

SELECT SCOPE_IDENTITY()

那么如何在我的UI中获得Scope_Identity

0 个答案:

没有答案