Fail to update relational table in access database using VB.NET - database

I am using access as my database in vb.net
I am using the drag and drop datasource approach to set up its dataset, data grid view , table adapter, table binding source.
I have two table , A and B
A is the parent table, B is children table
So there is a foreign key (say A.id )in B
When i tried to edit A and save it.
There will be an error come out.
It told me that B has a related record of A,
so i cannot modify or del A
I feel very confused of what it means
I did not edit column id in A (which is a foreign key in B) , i just edit others column
I don't understand why i still cannot save it
When i try to save :
the tableAdapterManager is using UpdateAll Method to update whole dataset
I tried to use the tableAdapter of A and B to update their individual dataset.
It comes out the same result no matter what the order of tableAdapter update method is
Really thanks someone who can answer my question :):)

Related

Is it possible to create a view where deleted rows in the original table are kept

I have a table COMPANY where companies are kept. I want to create a view of that table, let's name it COMPANY_CDC but with one caveat:
When an entry in the original table is deleted, I want to set a deleted flag on the view entry instead of deleting it.
EDIT Why soft deletes? The point is that im performing change data capture using JDBC, and JDBC is only able to capture soft deletes. Inserts / updates are no problem.
If this cannot be done by using a view, what would be an alternative solution?
You can insert deleted values in another table using trigger
, and with join of these two table you can create your view.

Transfer data from one column to a different column in a different table

I've got table A and table B in a database. I'm trying to move the column in table A to table B without losing any data. Not sure if its best to move the column somehow or make a whole new column in table B then copy the data over?
The problem is that the database is already in production and I don't want the clients to lose the data that is currently stored in column X in table A. I thought of making a migration to create the same column X in table B, and then somehow copying the data there. I am not sure how to do that, and I couldn't find a similar problem here.
if you have phpmyadmin you can do this pretty easily. this command should work:
INSERT INTO `tabletwo.columnb` (SELECT 'columna' FROM tableone)
Always back up the dbs, load local and try this, never live lol. I'm sure your aware. :)
Note: columna and columnb are placeholder for your actual column names
I think you can create the migration table to create de column on table B.
After you can use tinker ("php artisan tinker" on the terminal) to move the desired data on the table A to the B.

How do I automatically populate a new table in MS-Access with info from an existing table?

I am very new to MS Access and I am struggling with some things that seem like they should be the most basic. I have imported a table of data from Excel and have defined the data types for the fields. I have no problem there, but now I want to make a new table that has as a primary key one of the fields from the imported table. It looks like I can manually create this table, set the relationship, and then go back and type in each record associated with the new primary key, but this seems completely ridiculous. Surely there must be a way to automatically create one record for each unique instance in the matching field from the original table. Yet, I've scrolled through hundreds of pages of Access tutorials and Googled the question and found no satisfactory guidance.
Do I completely misunderstand what Access is all about? How do I create a new table with entries from a field on an existing table? What am I missing?
You don't specify which version of Access you are using, the suggestions listed below apply to 2010, but should be similar is other versions.
You can create new tables from existing tables using either a 'Make Table' option after selecting 'Create' -> 'Query Design', or you can manually create your table first, then use an 'Append' query.
Without knowing the design of your table it's hard to get more descriptive.
Are you populating your new table's primary key ahead of time, or relying on Auto Number to do it (preferred method)?

Visual Studio 2013 LightSwitch How to limit options in popup window when adding linked field data?

I have Visual Studio 2013 LightSwitch. My app is deployed to Azure. My SQL database is on Azure. Tables and links are created and working.
Problem 1: In Table A, when adding or updating data, I want to select data from fields in records based on primary key in other tables. Add and update data works. But my popup "X" list is way too long. I want the popup "X" when adding or updating record in Table A to only give me the choice of records from Table B that matches the data I entered in a previous field in Table A, not all the records from Table B.
Problem 2: Then while adding or updating Table A, I want the data from certain fields of the selected record in Table B to be transferred to certain fields in Table A. (Let's say - If I select "ABC" from the popup "X" in Field 2 in Table A, then when I am selecting something from the popup "X" in Field 3 in Table A, I want to select only from the records in Table B that match "ABC" in the primary key field of Table B, not all the records.
Problem 3: If the popup "X" list doesn't include the necessary record to put in Table A, then I want to add a record in Table B to include it in the popup list.
Problem 4: How do I get my popup "X" list to include more than one field? Is creating a new combined field the preferred way?
Problem 4: I also need some good help with user text input and getting the text into my online database. The thought of using an Intrinsic Database gives me the willies.
In your detailed solution, remember I am more familiar with Visual Basic than C#. Thanks.
I'm not quite sure what you mean by popup X list but I'm going to assume you mean an Auto Complete Box control as that would be the default control for linked data. To achieve what you want for problem 1, you need to create a query on Table B with a parameter for the selection field of Table A. You then assign that query to the Auto Complete Box by changing its Choices setting from Auto to your new query. Changing your selection on Table A automatically filters the available selections in your query on Table B.
Beth Massi explains in detail here - there isn't much code involved but her examples are in VB. I'd figure out problem 1 first and then see if that helps clarify the remaining ones.

inserting into a view in SQL server

I have a SQL Server as backend and use ms access as frontend.
I have two tables (persons and managers), manager is derived from persons (a 1:1 relation), thus i created a view managersFull which is basically a:
SELECT *
FROM `managers` `m`
INNER JOIN `persons` `p`
ON `m`.`id` = `p`.`id`
id in persons is autoincrementing and the primary key, id in managers is the primary key and a foreign key, referencing persons.id
now i want to be able to insert a new dataset with a form in ms access, but i can’t get it to work. no error message, no status line, nothing. the new rows aren’t inserted, and i have to press escape to cancel my changes to get back to design view in ms access.
i’m talking about a managers form and i want to be able to enter manager AND person information at the same time in a single form
my question is now: is it possible what i want to do here? if not, is there a “simple” workaround using after insert triggers or some lines of vba code?
thanks in advance
The problem is that your view is across several tables. If you access multiple tables you could update or insert in only one of them.
Please also check the MSDN for more detailed information on restrictions and on proper strategies for view updates
Assuming ODBC, some things to consider:
make sure you have a timestamp field in the person table, and that it is returned in your managers view. You also probably need the real PK of the person table in the manager view (I'm assuming your view takes the FK used for the self-join and aliases it as the ID field -- I wouldn't do that myself, as it is confusing. Instead, I'd use the real foreign key name in the managers view, and let the PK stand on its own with its real name).
try the Jet/ACE-specific DISTINCTROW predicate in your recordsource. With Jet/ACE back ends, this often makes it possible to insert into both tables when it's otherwise impossible. I don't know for certain if Jet will be smart enough to tell SQL Server to do the right thing, though.
if neither of those things works, change your form to use a recordsource based on your person table, and use a combo box based on the managers view as the control with which you edit the record to relate the person to a manager.
Ilya Kochetov pointed out that you can only update one table, but the work-around would be to apply the updates to the fields on one table and then the other. This solution assumes that the only access you have to these two tables is through this view and that you are not allowed to create a stored procedure to take care of this.
To model and maintain two related tables in access you don’t use a query or view that is a join of both tables. What you do is use a main form, and drop in a sub-form that is based on the child table. If the link master and child setting in the sub-form is set correctly, then you not need to write any code and access will insert the person’s id in the link field.
So, don’t use a joined table here. Simply use a form + sub-form setup and you be able to edit and maintain the data and the data in the related child table.
This means you base the form on the table, and not a view. And you base the sub-form on the child table. So, don't use a view here.

Resources