0

I'm using Visual Studio 2017 to revise an ASP.NET C# Web Forms application. The Linq-to-SQL designer already has tables mapped and the data context already had been created. I've added several stored procedures to the database, and added them by dragging from Server Explorer onto the methods pane of the O/R designer.

In my code behind page, I've written the following code to call my stored procedure:

private void RunResponses(int iStudyID )
{
    DataTable dt = new DataTable();

    dt = GetResponses(iStudyID);

    if (dt.Rows.Count > 0)
    {
        gvStudyResponseData.DataSource = dt;
        gvStudyResponseData.DataBind();
        // Session["dtAnalysisReport"] = dt;
    }
    else   // No records then create a dummy record to make Gridview still show up...
    {
        gvStudyResponseData.DataSource = null;
        gvStudyResponseData.DataBind();
    }
}

private DataTable GetResponses(int iStudyID)
{
    //string sSQL = "";
    //SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString);
    //DataTable dt = new DataTable();

    //sSQL = "EXEC spGetAnalysisReport @StudyID=" + iStudyID.ToString();
    //Debug.WriteLine(sSQL);

    DataTable dt = new DataTable();

    using (PROTOTYPING db = new PROTOTYPING(ConfigurationManager.ConnectionStrings["SQL"].ConnectionString))
    {
        try
        {
            gvStudyResponseData.DataSource = db.spGetAnalysisReport(iStudyID);
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            dt.Dispose();
        }

        return dt;
    }
}

My intent is to call RunResponses on Page_Load, so that the data for a given StudyID is hydrating a gvStudyResponseData gridview. PROTOTYPING is the data context automatically generated by the Linq-to-SQL designer.

The full error is

Compiler Error Message: CS1061: 'PROTOTYPING' does not contain a definition for 'spGetAnalysisReport' and no extension method 'spGetAnalysisReport' accepting a first argument of type 'PROTOTYPING' could be found (are you missing a using directive or an assembly reference?)

How do I ensure that the spGetAnalysisReport stored procedure is properly called by the code behind and that it is adequately mapped to the stored procedure in the database?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
SidC
  • 3,175
  • 14
  • 70
  • 132
  • Your problem is a little bit unclear, can you provide exact CS1061 message and is that error occurred when calling `gvStudyResponseData.DataSource = db.spGetAnalysisReport(iStudyID);`? – Tetsuya Yamamoto Feb 12 '18 at 02:55
  • @TetsuyaYamamoto Error message is now included. The error occurs on the line you mentioned in your comment. – SidC Feb 12 '18 at 03:35
  • I believe you have reference issue when calling that SP with `PROTOTYPING` context, check if namespace provided by designer.cs file (which included in same folder with DBML) referenced properly and `spGetAnalysisReport` exists there. – Tetsuya Yamamoto Feb 12 '18 at 03:58
  • @TetsuyaYamamoto It turns out that the Prototyping.designer.cs does not contain an implementation of spGetAnalysisReport. If I manually add an entry to this designer, wont future updates potentially overwrite it? – SidC Feb 12 '18 at 04:49
  • 1
    Are you want to update existing DBML file which includes `spGetAnalysisReport` procedure then? Check this reference for LINQ to SQL DBML update: https://stackoverflow.com/questions/1110171/how-do-i-update-a-linq-to-sql-dbml-file. – Tetsuya Yamamoto Feb 12 '18 at 04:53

0 Answers0