.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

HELP: Creating an ActionResult method to display a particular database record using Entity Framework

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :ASP.Net
 

Hi All,

I have an ActionResult method that displays records from a database table (below):

namespace STD.Controllers
{
    public class StudentController: Controller
    {
        StudentEntities stud;
        
        public StudentController()
    {
        stud= new StudentEntities ();

    }

        public ActionResult Index()
        {
            ViewData.Model = stud.StudentTable.ToList();
            return View();

        }
}

I want to design a method "ActionResult Student()" that accepts "Student ID" as a parameter and displays record for that particular student only.

What do I need to do to make this happen? Could anyone please help me with this?

Thanks in advance

 




View Complete Post


More Related Resource Links

How to display image from database using MVC2 & Entity framework.

  

Hello,


I am very new to MVC and entity I have being searching all over the internet on how to do this. Please help.


I need to do a site similar to http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx but don't know how to display or retrieve the images as in the above website.


Thank you so much!


Multiple database support with Entity Framework

  
One of the features introduced in Entity Framework is being database independent. Which mean each database provider can support Entity Framework by implementing its provider.

This feature allows you build applications independent from the underplaying database provider. In this post I'm going to show how to build an application that support multiple databases using same conceptual model made by Entity Framework.

Creating a Generic Entity Framework 4.0 Repository

  
With .NET 4.0 right around the corner, I thought it would be cool to download Visual Studio 2010 beta 2 and start playing around with the next release of Entity Framework.

The initial release of Entity Framework came with a great deal of criticism. To make matters worse, there was a large uproar when it was rumored that Microsoft would be abandoning LINQ to SQL, in favor of Entity Framework. This was because, at the time, many developers felt Entity Framework was an inferior technology to LINQ to SQL. To set things right, Microsoft proactively moved forward with improving Entity Framework, in time for the 4.0 release of the .NET Framework. This is good news because my initial impressions, so far, have been nothing but positive.

Update Database Schema without redeployment in Entity Framework

  
Hello. we build an app with 2 layers i.e the presentation and the Business layer which holds the business logic and have the entity framework provide us wtih entities. my question here is is there a way we can change the database schema and not have to redeploy the app to the client.  

Custom Entity Framework template and access to the database type

  
First and foremost ... I already made a few changes in the template, the most important one changing the methods generated for stored procedures with OUTPUT parameters and no resultset so that instead of instantiating a few OutputParameter objects, passing them to the method and extracting the values (all without any type checking) you just call the method with a few "out someType?" parameters so I do not need the very basics. I am totally confused by all those GlobalItem, EdmProperty, BuiltInTypeKind, TypeUsage and all this made of objects, all alike and all different though so as soon as I need more data than what's already used by the template I run into problems :-(What I would like is to change the WritePrimitiveTypeProperty() so that it outputs [StringLength(xxx)]  for all char, varchar, nchar and nvarchar properties. But I can't find a way to get from an EdmProperty in the model to the database type in the store.Can anyone help me?In case anyone is interested here's the modified stored procedure mapping code for the template. The first code replaces the original in the .tt: //////// //////// Write EntityContainer and ObjectContext Function Import methods. //////// region.Begin(GetResourceString("Template_RegionFunctionImports")); foreach (EdmFunction edmFunction in container.FunctionIm

how do I search record from database and display that in Datagridview.

  
hi,I am working in windows application.I wanted to search record while entering into textbox and respective data should be displayed in datagridview..

why two records are inserting in database using Entity Framework??

  

Hello,

i am using entity framework to access the database to insert/fetch data from database.

consider i am having two tables "AssetCheckList" and "TaskRecheckDetails"

AssetChecklist  Table

AssetChecklistID

AssetName

 

TaskRecheckDetails

TaskRecheckDetailsID

ParentAssetChecklistiID - Forigen Key of AssetCheckListID

RecheckAssetChecklistID -  Forigen Key of AssetCheckListID

 

when inserting the data in TaskRecheckDetails table two records are inserted with same details.

why and how to resolve it.

 

please help.

 

Thanks!

 


Databinding of WPF DataGrid with database via ADO.NET Entity framework

  
I develop WPF 4.0 desktop-based application that has to work with SQL Server database. In order to connect database with my GUI WPF-application I decided to use ADO.Net Entity Framework. I made edmx-connection, all works as expected, I see the structure of my DB in model browser.

After that in WinWorkers.xaml.cs I wrote basic LINQ-query that returns all data from tbl_users and I put it to IBindingList, here is a code fragment:
//databinding with database via LINQ query
IBindingList users = ((from d in App.glidusContext.tbl_users
            select new { d.userID, d.userName, d.userPassword }
          ) as IListSource).GetList() as IBindingList;

In order to show this data I chose to use DataGrid control inside of XAML-code, here is a code fragment of that:
<!--databinded content from database-->
<DataGrid 

Could not establish connection database. ASP.NET Membership and Entity Framework

  

Ok, so this is my first Solution using the Entity Framework (EF). Here are my steps so far:

1) Created Database named: BSA with an owner of username/password (AspNetServicesUser/password)
2) Created Entity Data Model (EDM) in a separate project (contained within the same solution)
3) Created an ASP.NET Web Application with basic functionality (new project within the same solution)
4) Added Reference to the EDM in Web App and added Connection String to the EF
5) Decided I wanted ASP.NET Membership added to the Web App
6) Configured SQL Server for Application Services using aspnet_regsql.exe on BSA database

Now, I need to know:
a) Should I keep the ASP.NET Membership Tables in a Separate DB altogether?
b) Should I update the EDM to include the ASP.NET Membership Tables?
c) Then, how do I create the connectionString for the Web.config file in the WebApp?


FYI: I get this error using the ASP.NET Configuration Tool under the "Security" Tab:
Login failed for user 'AspNetServicesUser'.

FYI: I get this error using the ASP.NET Configuration Tool under the "Provider" Tab --> Select a single provider for all site management data --> Test
Could not establish a connection to the database. 
If you have not yet created the SQL Server database, exit the

Unable to connect to Database | ASP.NET Membership and Entity Framework

  



Ok, so this is my first Solution using the Entity Framework (EF). Here are my steps so far:

1) Created Database named: BSA with an owner of username/password (AspNetServicesUser/password)
2) Created Entity Data Model (EDM) in a separate project (contained within the same solution)
3) Created an ASP.NET Web Application with basic functionality (new project within the same solution)
4) Added Reference to the EDM in Web App and added Connection String to the EF
5) Decided I wanted ASP.NET Membership added to the Web App
6) Configured SQL Server for Application Services using aspnet_regsql.exe on BSA database


Now, I need to know: 
a) How do I create the connectionString for the Web.config file in the WebApp?


Errors I receive:

I get this error using the ASP.NET Configuration Tool under the "Security" Tab:

Login failed for user 'AspNetServicesUser'.


I get this error using the ASP.NET Configuration Tool under the "Provider" Tab --> Select a single provider for all site management data --> Test

Could not establish a connection to the database. 

If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database

display a record count from sql database connection

  

sometimes learning asp.net feels so heavy handed compared to some of the general purpose scripting languages like php.  for examples, all i want to do is create a sql connection that pulls a row count and displays that number.  I don't need a grid, list, detail page, etc., nothing this heavy... a simply query that will display a simple bit of text.  for the life of me I can't figure out how to do it.  Using these controls, I'm not in the code behind with the query, so I wouldn't attach this to a label (or would i), and there's nothing i see in the toolbox that does what i want.  Perhaps i'm too accustomed to php but it feels like with asp.net, major things are simple, and simple things are hard.  any help would be appreciated.  i'm trying to convert my career to c#.net


how to change the database while using Ado.Net entity framework?

  

HI....

how to change the database while using ADO.Net Entity Framework?  

I have two identical databases. I want to change the db. Can i change it through web.Config?

Like LINQ to SQL ?

 

 

 


GridView inline Master/Detail record display

  
This code drop is part of a smash and grab series. If you're in a rush, you can just grab this code and insert it into your application, no understanding is required. When you have some time (ya, right) you may want to review the source code.

ASP.NET 4.0 Dynamic Data and Many to Many Entity Framework Entities

  
I did not play much with Dynamic Data controls in VS2008 and just made a cool discovery in VS2010 Beta 2. This may not even be new, but as I'm sitting 30,000+ feet over the Atlantic ocean, I don't have access to VS2008 at the moment to check.

Store and Display Images from MS Access Database Using C#

  
There is only the difference of coding syntax to stream the binary data of image content type to upload it into MS Access Database using C#/VB in ASP.Net 2.0

Namespaces required:-
using System.Data.OleDb;

OleDb is used to connect the web site forms with MS Access Database using Microsoft.Jet.OLEDB.4.0

Entity Framework 4 Tips for WinForms Development

  
I've been recently working on a smart client (WinForms) application backed by Entitiy Framework 4 (EF4) on Visual Studio 2010. In this blog post I will try to give you some tips regarding some limitations and points to be careful about EF4.

Does this look correct for saving a file/ new record to a database

  

So thank you for all your help so far, So I think i got this right,
but would like for you all to look it over to see if there is any
areas I might run into trouble with:

//using asp.net mvc 2
the table (sql server 2005, using entities framework)
"Pattern_Media"
table fields
"Pattern_Media_GUID  uniqueid 
"Pattern_GUID  uniqueid
"Media varbinary(max)  
"height int
"Width int
"Media_Type String (50)


the form:
<h2> Add Media to this pattern</h2>
<% Html.EnableClientValidation(); %>
<% Html.BeginForm("AddMedia", "Pattern", new { id= Model.Pattern_Guid} , FormMethod.Post, new {enctype = "multipart/form-data"}); %>
   
    <%: Html.Label("height") %>
    <%: Html.TextBox("height") %>

    <%: Html.Label("width") %>
    <%: Html.TextBox("width") %>

    <%: Html.Label("Media") %>
    <input type="file" id="Media" name="Media" />
   
    <input type="submit" name=

Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend