GridView issues ASP.NET / ADO Entities - asp.net

I am fairly new to working with ASP controls. I am having some issues with a project. This project is fairly large and my team has placed the ADO.NET emtity inside the same solution but placed into a different project inside Visual Studio 2010. The original db was built through SQL Server 2008. I was wondering if it would be possible to connect a GridView control to this entity in order to show certain aspects of it?
Also, If not possible, we have a class Customer which has certain members (name, dob, ssn,...etc) and functions that will pull these customers from the db through the ADO.NET. Could I populate the GridView with a a list of instances of this class?
something like
List<Customers> CustList = new List<Customers>();
....populate the list.....
Gridview.DataSource = CustList;
Gridbiew.DataBind();

Sure you can! Just add a reference the other project from the one that has the GridView, and set the DataSource property of the GridView to the entity that is in the other project. Indeed, this is a common design in applications, to separate them by "layers"(also criticised a lot).
Hope it helps,

Related

spreadsheet like asp.net and dynamic view

I want to create an application that users can select fields from database table and create a spreadsheet by those data. Is any control or sample to implement it?
Getting the schema of table varies from database to database.
No matter which database you use, it would be easy to get the list of columns and let the user select which columns to show.
To create a speardsheet you should look at these controls ASP.NET Real World Controls
These custom controls enable you to create excel like grids in asp.net. It is open source allowing you to extend them as may be needed by your project.

Adding table from another database to ASP.NET Dynamic Data + Entity Framework

I have a table in another database I would like to scaffold via ASP.NET Dynamic Data and incorporate into my existing Entity Model - is there anyway to do this? (eg using a view or other mechanism or customize the view, edit or insert operations via ad-hoc SQL or stored procedures?)
I don't want to replicate the entire DynamicData sub-folder structure and create another entity model for just one table
I was able to solve this by manually creating an entity in the SSDL and CSDL sections of the .edmx file by using a DefiningQuery and then defining the EntitySets for my entity class
I also added insert / update / delete Function elements to the SSDL with inline SQL using the CommandText property
At this point I had enough to let the Designer map the CRUD methods to these inline SQL functions I defined
It's a little tricky but it works and the general approach opens up many possibilities I had not thought about

Using ExecuteQuery() with entity framework, entity class

I am trying to jump from ASP Classic to asp.net. I have followed tutorials to get Entity Framework and LINQ to connect to my test database, but I am having difficulties figuring out ExecuteQuery(). I believe the problem is that I need an "entity class" for my database, but I can't figure out how to do it. Here is my simple code:
Dim db as New TestModel.TestEntity
Dim results AS IEnumerable(OF ???) = db.ExecuteQuery(Of ???)("Select * from Table1")
From the microsoft example site, they use an entity class called Customers, but I don't understand what that means.
Entity Framework comes with a visual designer. In that designer, you connect to your existing database, and you select all the tables (and possibly views) from your database that you want to work with.
From that selection, EF will generate entity classes one for each of your tables, e.g. if you have a Customers table, you'll get a Customer class, if you have a Products table, you get a Product class.
Those classes represent (by default) your table structure 1:1 - e.g. each column in your table gets translated into a property on the class.
Once you have that, you're no longer dealing with SQL statements and stuff like ExecuteQuery() - you leave that to EF to handle for you.
You just ask for what you need, e.g. all your customers from a given state:
var ohioCustomers = from c in dbContext.Customers
where c.State = "OH"
select c;
This statement will return an IEnumerable<Customer> - a list of customers that matches your search criteria.

Generate ASP.NET UserControl from Database

Is there any existing software for generating a UserControl from a table of a database?
For example, my table contain 3 fields : name , last name , age.
The software generates a user control that has 3 labels and textboxes with validation and submit button and a gridview for displaying information , etc...
Thanks all.
You might want to look into Dynamic Data. It's an ASP.NET framework developed by Microsoft that automatically generates common UI elements based on Linq to SQL or Entity Framework objects (which are trivially easy to generate from a simple table like the one you mention.)
What you describe sounds an awful lot like UI "scaffolding". Take a look at the following article and related question:
ASP.NET Scaffolding/Templating CRUD Solutions
Dynamic Data
Here's one more O/R mapper capable of scaffolding (generating UI from database):
http://www.subsonicproject.com/

LinqDataSource wizard table list is not refreshing after updating LinqToSql classes

I have changed my dbml file like this.
I have deleted all the tables and stored procs.
I added new tables and stored procs from a new database.
In the code-behind, I can access the new tables and stored procs. However, in the LinqDataSource using the same dbContext when I'm trying to configure the LinqDataSource. I can see all the old tables in the wizard drop-down.
How to refresh the the wizard drop-down so that I can select the newly added tables?
Deleting the old LinqDataSourceand adding a new one is not working.
After creating your new dbml, rebuild the solution. The tables should be shown in the wizard then.

Resources