MVC :: Replace A ID Value (a Foreign Key) In A View By Its Value?
Jun 17, 2010
As i start to work with MVC simple things are not so simple. I have a view that renders correctly a single table of my Database (using Entitry framework created automatically by visual from my SQL database).The table show everything including the foreign key and i i seeking for replacing the foreign key by a friendly name of my foreign table.In the controleur i have the following code :
public
ActionResult Index()"Equipement"]
= new
SelectList(_entities.T_E_EQUIPEMENTS_RESEAU_EQP.ToList(),
"EQP_ID",
"EQP_NOM");
return View(_entities.T_E_CONSOMMATEURS_CSO.ToList());
both table are joined by the foreign key CSO_EQP_ID and the primary key EQP_IDI have no clue of what to define in the view ?Any exemple of this simple need will be welcome.
View 3 Replies
Similar Messages:
Apr 17, 2010
but I am new with MVC and database-driven applications.
I hava a table with Cities (ID,Name) and one with Businesses(ID,CityID,Name). The later has a foreign key relationship with the first table.
I used a linq-to-SQL class to create my models.
My problem is that I need to access the City Name(not the ID) when displaying the Business Model View.
How can I do this? if from my controller I call the View passing the auto-generated Business Model, I only have access to the ID.
View 2 Replies
Aug 14, 2010
I have a search button ..The result will be displayed in grid view if the button is pressed .. i am able to do it
But now i want to do like this ..that is my grid view is only displaying the ResultId .. I want to display the ResultName rather than resultID in the table
View 5 Replies
Mar 8, 2011
I am using Entity Frameowrk as the ORM. I am new to MVC and trying to develop a samll module as a learning project.
Now I am stuck with an issue for which I can't seem to find out answer on web. The issue is :
I have two tables mapped as entities - Tenant_Definition and Contact
Tenant_Definition { Tenant_ID , Desc, Contact_ID}
Contact {Contact_ID, Company_Name,Company_Address,Person_Name, Person_Phone_Mobile}
My View has to present a form that shows Tenant Desc and Contact related fields. The index view works fine and shows the desired values.
But, the create view isn't working out. In the create view, i am planning to do -
1. creating a new contact entity instance and saving it in db
2. Then creating a new tenant entity instance using the new contact_id and save it to the DB.
However, the code doesn't seem to be inserting any value inside Contacts table. It inserts null value.Below is the code snippet of my Create Controller -
[HttpPost]
public ActionResult Create(FormCollection collection)
{
var newContact = new Contact();[code]....
View 6 Replies
Jul 26, 2010
I have a database with a 1 to many relationship in SQL Server 2008. I have created a formview in VS2008 to insert records into the child table. However I can't set the foreign key to automatically insert this value. If I manually type in a value the insert works but I need it to pick up the fk ID automatically from the master table. How can I do this?
The master table: tblTopic has ID int auto increment primary key and the child table has ID int auto increment primary key and TopicID int allow duplicates no nulls, foreign key. I have set updates to cascade in the relationship.
My insert statement is INSERT INTO tblTopic (TopicID, Comment, SubmittedBy) VALUES (@TopicID, @Comment,@SubmittedBy). The TopicID keeps throwing the error, this is the foreign key.
This is the first time I have tried to do this, so apologies if it's really obvious but I'm on a bit of learning curve.
View 10 Replies
Apr 28, 2010
I have a vb.net page that has a editable detailsview. When a user wants to erase the data for a field, they highlight the data, and delete/backspace over it, and click update. However, the original data is still saved. If they are replacing the current data with new data, that works fine and updates/saves correctly. This problem only happens when the current data needs to be removed.
View 6 Replies
Sep 13, 2010
1 - Is it necessary to have foreign key to obtain a Relation in Entity Framework between each entity.?
2 - I have a Language Table and many many table with a foreign key related to the language table. Is it right to add this foreign key or I should do something else ?
Ex:
Language
LangID
LangName
TableTextA
TblAID
TextInfo
LangID
TableTextB
TblBID
TextInfo
LangID
TableTextC
TblCID
TextInfo
LangID
etc ...
View 1 Replies
Jun 18, 2010
I need to replace <span> entries in a string to legacy html code because it's going to be used in a report for Crystal Reports. <b> works with Crystal, but the<span>'s do not.
Here's the string which I'm trying to replace: <span style="font-weight: bold">%THIS CAN BE ANY TEXT%</span>. I want to replace it to
<b>%THIS CAN BE ANY TEXT%</b>.
[Code]....
View 5 Replies
Mar 15, 2011
How do you replace" with" using the replace method?
View 5 Replies
Mar 22, 2011
I had table had data about product photos and this table had a relation to product table and product may be has more than Image. I did my code well to get all images for product by productID query string but only first image retrieved. Note that ProductID in handler page is a foreign key into the Photobank images table, also I note that productID had value of ID table didnot the productID:
stored proc:
ALTER proc [dbo].[SP_GetPhotoBank]
(
@ProductID Int
)
as
[Code].....
View 5 Replies
Jan 8, 2011
Lets say there's a table Table1 with Primary key as "MainID" and this MainID is being used as a Foreign key in many tables.
Now when I try and delete a record from Table1 who's MainID as foreign key is being used in some child tables, then it throws this exception that "Foreign key conflict n stuff"..
Now I want to design my Delete Strored procedure in such a way that first of all checks ALL the child t ables that have that foreign key column "MainID" and if MainID from Table1 is being used in any of the child tables it should return 0 . Based on this 0 value I want an alert box to show that will say "Still in use or watever" and wont let the user delete that record unless ALL the records in child tables have been deleted that were using that mainID from table1.
I can't use ON DELETE CASCADE. I want the user to delete child table records manually one by one. Only after child table records using the MainID have been deleted that the user can delete record from Table1
View 1 Replies
Jun 22, 2010
I've got 2 tables where each has a primary key which is also the identifier (Both fields called "id" in each table) In the "picture" table as one of the fields I've got the photoalbumid (The id of the "photoalbum" table). This field is just an int field. I'm getting the following error: "Cannot insert explicit value for identity column in table 'Picture' when IDENTITY_INSERT is set to OFF" Can anyone give me some advise? It's such a basic thing I would hope that there's just something small in the creation of the database that I've missed out. Let me know if you need more info.
View 9 Replies
Oct 5, 2010
I've two table
a). Country
1.CountryId -PK
2. Country Name
b)City
1.CityId---PK
2.CityName
3.CountryId --FK to Country table
and my code is FWUDataContextDataContext CityContext = new FWUDataContextDataContext();
View 3 Replies
Jul 24, 2010
I am trying to build the MVC Music Store from ASP.Net, my only problem is that the tutorial is made for asp.net 4.0 C# and mvc2 an i am creating it with asp.net 3.5 VB mvc 1. For now i found out a lot of thing wich will work much better in the new frameworks, but my webhost still doesnt support it, because they have some problemms with PLESK.
Now i have a problem i cant figure out, i cant update data from a dropdown list, in the database using the updatemodel, that are foreign keys. Just all other data wich are not foreign keys and primary keys are updateable. These are automaticly created in the sql entity model.
Here is my code.
[code]....
View 3 Replies
Feb 17, 2011
I have the following code
Customer currentCustomer = new Customer();
when i do currentCustomer. In the drop down I can see all the columns listed except one column which is a foriegn key from order table , how do i insert into intorder_fk
View 1 Replies
Sep 10, 2010
In my databse i have a databse tables
UserRole -UserID,UserName,RoleName.
Compaign - CompaignId,Region,CompaignName,LOB.
Employee -EmpNo,EmpName,CompignId
Timesheet -TimeId,EmpNo,Date.
I dont have primary key for Compaign Table CompaignId is Identity column. Now i want to use CompaignId in Employee Table because based on compaign user will retrieve employee data in Front end. Again Employee table doesn't have primary key. I am uploading excel file data to databse but in excel file there is no empNo so i cannot use primaryKey i have EmpName in excel file. How to solve this issue. How to use master table if possible create table structure for my requirements.
View 5 Replies
Nov 16, 2010
So I am working with a database and am trying to get my model code working.I have a situation where I have a table called accounts that for simplicity has 3 columns
accountid, accounttype, parentid
basically its a parent child relationship. if parentid is null its a parent, its not its a child of the accountid.Im running into problems getting the .edmx file mapping. parentid is a foriegn key on the table.
how can access the parentid column? i can see it in account navigation account1 but Im not sure how to get access to it in my linq query
View 3 Replies
Feb 22, 2011
I have an MVC3 with EF4 project. I have a screen for order .Order has 2 id's inside it for Billilng and Shipping AddressID .When I go and create a new order these fields render as single textboxes as Ids'Question is how can I render full address textboxes (addressline1,city,state,zip etc) do I have drop in the html markup for them? In that case while capturing the data back I willl have to go with classic way of retrieving name/value pair and then do insert into address bring back that identity and update the order record...?
Create(int customerID,FormCollection fc){}
So the main question is how can I do ModelBinding with foreign keys?
View 8 Replies
Mar 10, 2011
I have two tables, which is table 'A' and table 'B'. Table B contains a foreign key that is referenced to table 'A'. The question now is, could I used an option in my project in visual studio an 'Others specify'? I believed that it's not possible, isn't it?If I have a selection that is bound to a datasource then is it possible to make an option 'Others specify' without adding the specified value to the database, which in turn would not have a unique ID? Table B contains the table A ID PK field, and all values from table A to table B should contain a unique ID.
View 2 Replies
Apr 21, 2010
I have a database with the structure
Client
--------------
ClientID -> PK
FistName
LastName
AddressID -> FK to Address.AddressID
and
Address
--------------
AdressID -> PK
City
CityCode
I created an initial set of address so
0 - London - 1000
1 - Paris - 2000
2 - Madrid - 3000
3 - Lisbon - 4000
I'm using Visual Studio 2008 with MVC.
Framwork to use ADO.NET to create the model
My view is:
[Code]....
My model is just: ... Private _dataModel As New just2testDBEntities
[Code]....
When post it retun erro
{"Can not insert the value NULL into column 'City', table 'dbo.Address'; column does not allow nulls. INSERT fails. ... statement terminated."}What I was intended to do is to insert a client and not a client and an address.
View 5 Replies
Mar 1, 2010
I have 2 tables: Users and Accounts. The Accounts table has CreatedBy, UpdatedBy fields for audit purposes.
On my UI I need to display: ABC Inc. was last modified by "John Smith" - where John Smith is the UpdatedBy ID from the user's table.
In my DataContext file I have removed all relationships. Can anyone tell me how to retrieve the username for the foreign key.
View 6 Replies
Sep 7, 2010
How to delete values in case of foreign key?
[Code]....
View 8 Replies
Oct 18, 2010
I m try to insert record to table, its working well without foreignkey using Entity model. But i need to insert foreign key. I used the following query, its not working well via Entity model.
objFacility.FacilityCategoryReference.EntityKey =
new System.Data.EntityKey("testEntities.test",
"id", 10);
View 1 Replies
Feb 28, 2011
I am using Access 2003 Database and I need to retrieve list of a table's foreign keys and tables they are related to in C#. I used GetSchema() function of OleDbConnection as well as OdbcConnection classes. But It just returns the name of key among few other details.
OdbcConnection con = new OdbcConnection(conStr);
View 6 Replies
Dec 7, 2010
I am new to sql. I got this task to design a table in sql. It has for columns user_ID(PK, FK1) , WebSite_ID (PK, FK2), Create_Dt, Update_Dt How do I create PK and Fk1 and PK FK2 in sql server 2008 R2
View 3 Replies