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.
Related
Please if someone have an idea about what i'm searching about.
i'm develloping an application web with asp.net and sql server. I have used a gridview and i want to make every new user after login see the gridview clear in order to create its own values.
But The gridview must still related with the same table of the database.
I hope that you understand my problem and i'm sorry for my english.
Are the columns in the gird bound to columns of your users table or are they bound to it's own separate table?
If it's the latter, the table for the grid should have a column specifically for the users' id
for example, if the records for the gridview were held in table USER_GRIDVIEW_RECORDS:
ALTER TABLE USER_GRIDVIEW_RECORDS
ADD USER_ID INT NOT NULL;
This way you can set the DataSource of the grid to the result of the following query:
SELECT * FROM USER_GRIDVIEW_RECORDS
WHERE USER_ID = LOGED_IN_USER_ID
And write the records of the gridview back to the database with the following query.
INSERT INTO USER_GRIDVIEW_RECORDS (USER_ID, OTHER_COLUMN_NAMES, MORE_COLUMN_NAMES)
VALUES (LOGED_IN_USER_ID, 'Example value', 'another example')
If this isn't enough for you, give us some example code of how you query your server and about how you write the DataSet to the DataSource of your GridView
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'.
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 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'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.