Unable to update stored procedure in to 3 tier architecture in code first

119 views Asked by At

I have an existing project which is developed into 3-tier architecture pattern. It has BLL and DAL .dll files in reference.

Now I want to access a new Stored procedure which already created in ssms to use in this project. I create a method in to .cs file having Stored Procedure Name and Parameters of BLL. build the code and then tried to fetch the particular method from controller but controller didn't fetch the method which i developed in to .cs file.

  • MetaData File :-

    public int AddChapter(string dOCTitleID, string topicalTitleId, string partTitleId, string chapterNumber, string chapterTitles, string parentChapterId);

  • Method Created in Chapter.cs file :

    public int AddChapterSelect(int dOCTitleID, int topicalTitleId, int partTitleId, string chapterNumber, string chapterTitles, int subChapterId)
    {
         return dam.ExecuteDataSetByUpdate("USP_AddChapter", dOCTitleID, topicalTitleId, partTitleId, chapterNumber, chapterTitles, subChapterId);
    
    }
    

    Stored Procedure

    ALTER PROC [dbo].[USP_AddChapter]        
    (        
    @DOCTitleID int,        
    @TopicalTitleID int,        
    @PartTitleID int,        
    @ChapterNumber nvarchar(50),        
    @ChapterTitles nvarchar(max),        
    @SubChapterID int      
    )        
    as        
    begin            
         insert into Chapters(DOCTitleID,TopicalTitleID,PartTitleID,ChapterNumber,ChapterTitles,SubChapterID)        
     values(nullif(@DOCTitleID,0),nullif(@TopicalTitleID,0),nullif(@PartTitleID,0),@ChapterNumber,@ChapterTitles,nullif(@SubChapterID,0))            
    end
    

Please help out that, how can i update the SP in db and access to my Controller.

1

There are 1 answers

0
Chetan Pandey On

I just directly call the stored procedure from controller and add the namespace of existing DAL which have implemented DataAccessMethod.

Create a object of DataAccessMethod.

Steps here -

  • Add namespace -

                       using DAL;
    
  • Create Object of DAL's Data Access Method

             DataAccessMethod dm = new DataAccessMethod();
    
  • Create a method for calling Stored Procedure

    public int AddChapterSelect(string subchapterNumber, string subchapterTitles, string chapterId) { return dm.ExecuteDataSetByUpdate("USP_AddChapterSelect", subchapterNumber, subchapterTitles, chapterId); }

  • Called it in to My Function :

    protected void btnAddChapter_Click(object sender, EventArgs e) { if (ddlSelectDocumentTitle.SelectedItem.Value != "0") { int res = AddChapterSelect(txtSubChapterNumber.Text, txtSubChapterTitle.Text, ddlChapter_Popup.SelectedValue); if (res > 0) { lblSelectMsg.ForeColor = Color.Green; lblSelectMsg.Text = "Record saved successfully"; txtChapterNumber.Text = ""; txtChapterTitle.Text = ""; txtSubChapterNumber.Text = ""; txtSubChapterTitle.Text = ""; Bind_ddlChapter(); } } else { lblSelectMsg.ForeColor = Color.Green; lblSelectMsg.Text = "Please select document title"; } }

Thanks :)