0

一度に挿入するデータのセットが複数あります。たとえば、10 行です。

PlanIdテーブルには、 、MomEntryIdおよびの 3 つの列があります。CreatedBy

1 つの SQL ステートメントで 10 行すべてを挿入できますか?

これは私の Store プロシージャです。SP で 10 行の値を渡すにはどうすればよいですか。私はそれを検証する必要があり、それが価値があるかどうかも検証する必要がPlanIdあります。MomEntryIdgreater than zero

CREATE PROCEDURE SP_Document_Plan_Or_MomEntry_Insert
@PlanId int = null,
@MomEntryId int = null,
@CreatedBy varchar(20)  
AS
BEGIN
    if(@PlanId > 0)
    begin
        Insert into t_Document(PlanId,CreatedBy,CreatedDate)
        values
        (@PlanId,@CreatedBy,GETDATE())
    end
    else if (@MomEntryId>0)
    begin
        Insert into t_Document([MomEntryId],CreatedBy,CreatedDate)
        values
        (@MomEntryId,@CreatedBy,GETDATE())
    end
END
GO

以下は、パラメーターを渡すための私の C# コードです。

  cblCheckList.Items.Cast<ListItem>().ToList().ForEach(d =>
                    {
                        if(d.Selected)
                        {
                            momEntry.AddDocumentDetailForMomEntry(Convert.ToInt32(d.Value), Session["userId"].ToString());
                        }
                    });

これは Datalayer コード用Enterprise libraryです。ファイルを使用して DbHelper クラスを作成します。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for MOMGateway
/// </summary>
public class MOMGateway
{
    private MOMGateway()
    {
        //
        // TODO: Add constructor logic here
        //
    }

   ///
   /// This method perform insert operation in Document table
   ///
    public static int AddDocumentEntryforMomEntry(int momEntryId,string createdBy)
    {
        int i = Convert.ToInt32(DBHelper.GetDatabase().ExecuteScalar("SP_Document_Plan_Or_MomEntry_Insert",
                      null,momEntryId,createdBy));
        return i;
    }



}
4

1 に答える 1