I have two tables, category (pk) and foreign key table Item(fk).
In item table have itemid, item name,category I'd....and this category I'd is foreign key column with primary table...which is having category I'd, Category name.
And I have relationship between category table as parent and. Item table as child table....category I'd is the relationship between them. When I delete records based on itemid the records should be deleted from the application but maintained at backed level..as I do not want duplicate item...even I have deleted from application.
At Application level I am doing these things with textboxes for and drop down list which should category names.
If I have got you correctly, what you want to do is, maintain the data in the database table even if you delete it from the application interface.
If that is the case, you simply can add a column like 'isDeleted' in both of the tables in the database. In the delete event, just fire the update statement instead of actually deleting the record and set the 'isDeleted' field value to 'True'. At the time of displaying data from the tables, just select the records having 'isDeleted' value equals to 'False'.
Related
This question was asked to me recently, any suggestions are welcome.
There is a form containing company details of say 5 companies.>> C_ID, C_Name, c_Address. (Stored in Table Company)
Below there is a grid view which displays employee records and has insert functionality. the fields of grid view are say>> E_ID, E_Name, E_Address. (Stored in Table Employee)
Now this employee has to be mapped with one of the 5 companies. But there is no reference available. How to find the Foreign key? How to maintain relationship between the two Tables?
Add a new field in Employees Table named "C_ID" and make it a FK(foreign key) to be mapped in Company table..
after adding the field, right click Employees table click design. On the design right click and click relationship. Add new relationship, click Tables and Columns Specifical, on the dropdown choose Customer table and choose C_ID.
You'll need to add the column to map the relationship, and add the foreign key to enforce referential integrity for this relationship.
If the employee can be linked to only one company at a time:
(e.g. in Sql Server):
ALTER TABLE Employee ADD CompanyID INT;
ALTER TABLE Employee ADD CONSTRAINT FK_Employee_Company
FOREIGN KEY(Company_ID) REFERENCES Company(C_ID);
If the employee can be many to many to a company, e.g. part time, contractor, or tracking a history across multiple companies, then you will need a new junction table between employee and company to model this relationship.
I am newbie in asp.net technology. Recently I have been creating a form in asp.net. This form contains a gridview, which has columns names employee name, salary, location. These are extracted from the DB (master) having employee_id as primary key. When I click the update button in gridview, the control goes back to add employee.
PROBLEM:: I want to automatically update another table (slave), which has formula_id as primary key, salary, location, relatedheadid and this table should be temporary. i:e 1st master should execute and than the field values in mater table are to be updated in slave table.
I have a table called "orderDetails" which contains 4 fields:
OrderID // (primary key of Orders table)
ItemID // (primary key of Items table)
Amount
IsImportant
the primary key of orderDetails table is composed by the first two fields.
I have in my asp.net site a gridview which shows the order details of a selected order.
I'm trying to update a row in the gridview. the user can update only the Amount, IsImportant fileds.
For all the rows except the first one i'm getting this error when trying to update a row:
The property 'ItemID' is part of the object's key information and
cannot be modified.
I read that it is not possible to update the primary key but this is weird because
I'm not trying to update the primary key, only the rest of the fields
updating the first row in the gridview does succeed.
Thanks!
I'm not sure this is what you're looking for, but try to set the column of the problematic key to visible = false. Because when you do update it basically tries to updates ALL fields which appears on that row.
But it's still weird why the first row's update did succeed.
I have a sql view with multiple tables joined with union all. The view has a collumn id which is the primary key for each record (which can came from different tables).
The problem ism becuase the view results from a union, there might be more than one row with the same id.
In this cases Doctrine_Collection seems to automaticly group all the records by the id collumn making some records to disapear.
Is there any way to change this behavior?
If you really need to combine those records in a union, one way around that problem is to alias the id field for each subquery or table so that the id fields don't get combined.
I've created a new ASP.NET website. I've generated an Entity Data Model from my database and have dropped a entitydatasource and gridview onto my page and wired up the gridview to pull from the entitydatasource. Now I get columns like this:
id extension prefix did_flag len ten_id restriction_class_id sfc_id name_display building_id floor room phone_id department_id
In each case where the item is named something_id this reflects a foreign key relationship in the database - and I did choose to have the EDM expose foreign key relationships. I'd like to make it so the gridview pulls in the values for these foreign keys rather than just showing the ID numbers - so, for example, department_id might have a value of "101" right now but it should pull from the department table "Marketing".
I don't remember how I ever made it do this in the first place, but the natural action is to display the values - Dynamic Data handles this automatically, one does not have to tell it to do this.