Couldn't find modelDataContext - c#

Im trying to use LINQ in my ASP.NET/C# website. For that I need to access the class 'modelDataContext' which is a part of the LINQ namespace.
Im using Visual Studio 2010 Professional
This is my C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class admin_new_feed : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
modelDataContext data = new modelDataContext();
}
}
Full error message I get
Error 1 The type or namespace name 'modelDataContext' could not be
found (are you missing a using directive or an assembly
reference?)
Things i've tried, which doesn't solve problem
Adding the reference (Right-click solution, add reference - System.Data.Linq)
Re-create the website
Right clicking on the line, to see if the tab "Resolve" was there. But it wasn't.

Related

Error in calling db context in ASP. NET application [VISUAL STUDIO 2012]

In Visual Studio 2012, I have just started learning ASP.Net and got stuck in my first application with ADO. NET entity model. I have created a small table contact_master(id, name, phone, email) and trying to insert a row in the table using the entity. But I get below error,
ASP .NET 'contactEntities' does not contain a definition for
'contact_masters' and no extension method 'contact_masters' accepting
a first argument of type 'contactEntities' could be found (are you
missing a using directive or an assembly reference?)
Below is the code for page1.aspx.cs file.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class page1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
contactEntities obj = new contactEntities();
contact_master c = new contact_master();
c.email = "test#test.com";
c.name = "sdsd";
c.phone = "543634";
obj.contact_masters.save(c);
}
}
Below is how my solution explorer looks like
"obj.contact_masters.save(c);" contains the error :( Apologies if I messed up in terminologies.

default webform using and namespace queries

When creating webform in VS 2013, the codebehind contains several using alias but when I save the page all the using alias are removed. Only one using using System; is kept. Why is it so?
Also the code behind has namespace, when I see different web pages tutorials they simply start with public partial class. What is the difference ? Should I simply remove the namespace, does it effect my webpages ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Sample.UI.pages
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
1) If you aren't adding any extra code that would be accessible via a using statement, then you don't need any extra using statements.
2) public partial class refers to the fact that the class is split over 3 files. One is the aspx file, the designer.cs file, and the aspx.cs code behind. Do not remove any namespaces unless you know what you're doing. The CLR uses the assemblies namespaces to find code to execute.

New Form is not accessing in my project

I am a new programmer of C#.net I've been working on a project already have 6 to 7 forms in it on which I am working, last night when I add new form and try to access directly to this form in program.cs file then neither there is frmForm1 suggestion is coming and if I write it manually then the error arise
Error 2 , The type or namespace name 'frmForm2' could not be found
(are you missing a using directive or an assembly
reference?) C:\Users\Ahsan\Desktop\SurveyBuilder\SurveyBuilder\Program.cs 29 37 SurveyBuilder
Whenever there is a form named Form2.cs is in my project, tried to attach snap of it but due to low reputation(its my first question on this site) I am not able to attach.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SurveyBuilder
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
}
}

CS0234 - Cannot Instantiate C# class in ASP.NET

I made the same ASP.NET C# project in both VS2010 and MonoDevelop using these two classes among the standard files (Site.Master, Web.Config, Default.aspx, etc.) and recieve this same error (CS0234) seen at the bottom.
Login.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using mynamespace;
namespace mynamespace
{
public partial class Logon
{
public void btnClicked(object sender, EventArgs e)
{
//ERROR IS HERE:
mynamespace.Test session = new mynamespace.Test();
//Obviously, this doesn't work either:
Response.Write(session.echoUser());
}
}
}
Test.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using mynamespace;
namespace mynamespace
{
public class Test
{
public string echoUser()
{
return "foobar";
}
}
}
I recieve the same error in both IDEs, here is the MonoDevelop error:
The type or namespace 'Test' does not exist in the namespace 'mynamespace' (are you missing an assembly reference?) (CS0234) Logon.cs
Basically, the class Test refuses to instantiate. Any input is appreciated!
If you have that Test class in an ASP.Net web project, then you need to place it in the App_Code folder, not just anywhere in the site.
You need to refer the projects to each other, if you haven't done so yet. I'm guessing that you don't get the intellisense to show the class in the other namespace, right?
You can see the References on the right side (most cases) under your project view. You can right click there and choose to Add reference. Then you browse to the binaries from the pther projects. (You might be able to point to the project itself too - I don't have VS in front of me at the moment.)
Also, It's a convention to use camel case for namespaces, so it should be MyNameSpace.
If the classes are in the same project, you might want to skip using mynamespace and refer to the class by Test intead of mynamespace.Test.
If these are both in the same project, please check that both files are included in the project and have the "Build Action" property set to "Compile". Please also check that all of these namespaces have exactly matching spelling and casing.

Datacontext in LINQ. "Does not exist in the current context"

I keep on receiving this error message. I followed the instructions but it seems it is still not working? what is the solution for this? here's my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Linq;
using System.Data.Linq.Mapping;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MyDatabaseDataContext = new MyDatabaseDataContext(#"C:\Users\John\Documents\visual studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\MyDatabase.mdf");
}
}
}
Here's the stacktrace
Error 1 'WindowsFormsApplication1.Form1' does not contain a definition for 'Form1_Load' and no extension method 'Form1_Load' accepting a first argument of type 'WindowsFormsApplication1.Form1' could be found (are you missing a using directive or an assembly reference?) C:\Users\John\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs 92 55 WindowsFormsApplication1
This happens if you add an event handler in the designer, then delete the handler method.
Since you didn't delete the auto-generated code that adds the method to the event, you get a compiler error.
Go to the .Designer.cs file and delete the line with the error.

Categories