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?