1
Answer

From textbox input and button click :set query from database using Linq to Entity framework and display data (Visual studio 2010)

Ask a question
Bitini Lumbet

Bitini Lumbet

12y
3.4k
1
When user submit the search text in textbox by clicking the button I try to set query from database using  Linq to Entities framework  and display to gridview - I get error (Not that I am using visual studio 2010.
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication3
{
  public partial class _Default : System.Web.UI.Page
  {
  protected void Page_Load(object sender, EventArgs e)
  {
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  var searchText = TextBox1.Text;
  using (DBResearchEntities query = new DBResearchEntities())
  {
  var Articlequery = from t in query.article
  where t.Title == searchText
  select t;
  GridView1.DataSource = Articlequery;
  GridView1.DataBind();
  }
  }
  }
}


I get this error :
Server Error in '/' Application.
--------------------------------------------------------------------------------
The ObjectContext must be configured by 1) defining ContextTypeName, 2) defining both ConnectionString and DefaultContainerName, 3) defining ContextType, or 4) supplying it in the OnSelecting event.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The ObjectContext must be configured by 1) defining ContextTypeName, 2) defining both ConnectionString and DefaultContainerName, 3) defining ContextType, or 4) supplying it in the OnSelecting event.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 
Stack Trace:

[InvalidOperationException: The ObjectContext must be configured by 1) defining ContextTypeName, 2) defining both ConnectionString and DefaultContainerName, 3) defining ContextType, or 4) supplying it in the OnSelecting event.]
  System.Web.UI.WebControls.EntityDataSourceView.ConstructContext() +88613
  System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +76
  System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
  System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
  System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
  System.Web.UI.WebControls.GridView.DataBind() +4
  System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
  System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
  System.Web.UI.Control.EnsureChildControls() +102
  System.Web.UI.Control.PreRenderRecursiveInternal() +42
  System.Web.UI.Control.PreRenderRecursiveInternal() +175
  System.Web.UI.Control.PreRenderRecursiveInternal() +175
  System.Web.UI.Control.PreRenderRecursiveInternal() +175
  System.Web.UI.Control.PreRenderRecursiveInternal() +175
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
 



Answers (1)