| |

VerySource

 Forgot password?
 Register
Search
View: 587|Reply: 3

A question about Dataset. I hope the experts can answer it! Thank you.

[Copy link]

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Unknown

Post time: 2020-2-10 22:30:01
| Show all posts |Read mode
There are two tables A and B (different users). Table B has one more column than table A, and the remaining columns are all the same.
Now I want to implement such an operation, which is to add the data of table A to table B.

Idea: (Prerequisite: a dsA.xsd (dataset file) already exists but no dsB.xsd)
1. Take out all the data in table A and put it into datasetA.
2. Add a column to datasetA, write a value to this column, and get a modified datasetA.
3. Create a datasetB of B, and add the data of datasetA to datasetB
4. Save datasetB and update the database.

However, a problem occurred. Because in this project, to update a library table, you need to call a save method in the data layer. For example, if I want to update table A, I need to call the save method in the data layer file corresponding to A. Enter datasetA, the type is dsA. Then update according to different users.
Because there are so many similar tables, it is required that the type B tables use the data access layer of the type A tables (the type B tables have no other operations except to save the information of the table A)
Because the input type of the save method is a specific type, such as dsA (dsA.xsd), rather than an ordinary dataset, the structure of the table in dsA has been determined, one column less than B, and B has no data layer. So I have to call A's save method to save B, but it won't work. I would like to ask, is it possible to save in this case? Is there a way to dynamically add a column in dsA so that no errors occur due to the difference in the number of columns when saving. Thank you. If I didn't explain it. Excuse me. I'm waiting online! !!
Reply

Use magic Report

0

Threads

26

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-4-6 20:45:01
| Show all posts
Define the save method in the data layer as virtual, define a B table type inherited from the A table type, override the save method of the A table type to suit the data type of the B table
A a = new B ();
.....
a.save ();
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-4-9 13:45:01
| Show all posts
Following the original model will certainly not meet your requirements.
There must be a common way in the mode you use, that is, the ordinary Dataset way you said, you can use this interface to implement data updates, regardless of the structure of the B table.

Of course, there are some other ways, the pattern is used to plan the coding, but if it reaches the point of hindering the coding, the pattern must be reconstructed.
Reply

Use magic Report

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-4-11 19:00:01
| Show all posts
It seems that I can only discuss with the head.
But there is still a doubt. If I use the ordinary dataset method. The normal way is
Create an ordinary datasetB, then add the data of A to datasetB, and then save to the B table
. Can I update datasetA to B without creating datasetB? Do you want to change the state of the line. wrote
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list