How to perform “copy” / “paste” for a specific record of the table and its child nodes?










0















There is a database table. (MS Access)

On the basis of the table a tree is formed.



field ID - autoincrement (formed by the database).



Scenario:

1. User. Selects the node to copy;

2. User. Selects the node where to copy;

3. Program. Gets the string of the node to be copied;

4. Program. Copies the string "2 1 0 AA Node Level_2" and the associated strings as child lines (nodes) into the node "16 13 2 CC Node Level_2", which is specified as "recipient";

5. Program. Updates the database table based on changes to the DataTable.



Question.

How to programmatically “copy” and “insert” for a specific record of the table (DataTable) and its child nodes (rows) with any nesting of nodes?

The question means how to perform clause 3, clause 4?



As a result, additional records should appear in the source table.
ID // PrID // sorting // NodeName // field_1 // field_2 // field_3

18 16 0 AA Node Level_2

19 18 0 AAA Node Level_3

20 19 0 AAAA Node Level_4

21 19 1 AAAB Node Level_4

23 19 2 AAAC Node Level_4_Изм_3



Tree based on source table
Tree based on source table



public void connect()

string catBD = @"c:testvisualStudiocsharp11.accdb";
string conBD = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=0", catBD);

OleDbConnection connection = new OleDbConnection(conBD);

connection.Open();

string query1 = "SELECT * FROM TableTreeView_12_0";
OleDbCommand cmd1 = new OleDbCommand(query1, connection);


dt = new DataTable();

adapter = new OleDbDataAdapter(cmd1);
cb = new OleDbCommandBuilder(adapter);

adapter.Fill(dt);




Source table
ID // PrID // sorting // NodeName // field_1 // field_2 // field_3

1 0 0 A Node Level_1_изм_2

2 1 0 AA Node Level_2

3 2 0 AAA Node Level_3

4 3 0 AAAA Node Level_4

5 3 1 AAAB Node Level_4

6 3 2 AAAC Node Level_4_Изм_3

7 1 1 AB Node Level_2

8 1 2 AC Node Level_2

9 0 1 B Node Level_1

10 9 0 BA Node Level_2

11 9 1 BB Node Level_2

12 9 2 BC Node Level_2

13 0 2 C Node Level_1

14 13 0 CA Node Level_2

15 13 1 CB Node Level_2

16 13 2 CC Node Level_2

17 13 3 CD Node Level_2










share|improve this question
























  • So when the user copies node 2 into node 16 - node 2's PrID changes from 1 to 16, and all the children of node 2 become children of node 16, or do they stay children of node 2?

    – Zohar Peled
    Nov 15 '18 at 12:15











  • @ZoharPeled I updated the question.

    – eusataf
    Nov 15 '18 at 13:56











  • Well, basically you need to duplicate a record, and then repeat this for all the records associated with it. You might have a problem with the auto-increment columns.

    – Zohar Peled
    Nov 15 '18 at 14:08











  • @Zohar Peled You might have a problem with the auto-increment .. - Are you talking about field ID - autoincrement (formed by the database) .? I made it just by analogy. Are you talking about field ID - autoincrement (formed by the database) .? I made it just by analogy. 1. Option 1. Will it be correct to create an ID in the code? Example: ID-new record = maximum` ID` of table +1. 2. Option 2. Will the scenario be correct: Scenario: 2.0. we copy "parent". 2.1. save the "parent" in the database; 2.2. obtained from the database ID" parent "2.3. assign ID" parent "child entries;

    – eusataf
    Nov 15 '18 at 14:18











  • If the id column is auto-generated by the database, perhaps it's better to do the entire thing in a stored procedure and re-select. There are ways to ensure correctly handling the auto-increment in code, but without knowing what database you are working with, it's impossible to predict how will it handle newly added rows.

    – Zohar Peled
    Nov 15 '18 at 14:22















0















There is a database table. (MS Access)

On the basis of the table a tree is formed.



field ID - autoincrement (formed by the database).



Scenario:

1. User. Selects the node to copy;

2. User. Selects the node where to copy;

3. Program. Gets the string of the node to be copied;

4. Program. Copies the string "2 1 0 AA Node Level_2" and the associated strings as child lines (nodes) into the node "16 13 2 CC Node Level_2", which is specified as "recipient";

5. Program. Updates the database table based on changes to the DataTable.



Question.

How to programmatically “copy” and “insert” for a specific record of the table (DataTable) and its child nodes (rows) with any nesting of nodes?

The question means how to perform clause 3, clause 4?



As a result, additional records should appear in the source table.
ID // PrID // sorting // NodeName // field_1 // field_2 // field_3

18 16 0 AA Node Level_2

19 18 0 AAA Node Level_3

20 19 0 AAAA Node Level_4

21 19 1 AAAB Node Level_4

23 19 2 AAAC Node Level_4_Изм_3



Tree based on source table
Tree based on source table



public void connect()

string catBD = @"c:testvisualStudiocsharp11.accdb";
string conBD = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=0", catBD);

OleDbConnection connection = new OleDbConnection(conBD);

connection.Open();

string query1 = "SELECT * FROM TableTreeView_12_0";
OleDbCommand cmd1 = new OleDbCommand(query1, connection);


dt = new DataTable();

adapter = new OleDbDataAdapter(cmd1);
cb = new OleDbCommandBuilder(adapter);

adapter.Fill(dt);




Source table
ID // PrID // sorting // NodeName // field_1 // field_2 // field_3

1 0 0 A Node Level_1_изм_2

2 1 0 AA Node Level_2

3 2 0 AAA Node Level_3

4 3 0 AAAA Node Level_4

5 3 1 AAAB Node Level_4

6 3 2 AAAC Node Level_4_Изм_3

7 1 1 AB Node Level_2

8 1 2 AC Node Level_2

9 0 1 B Node Level_1

10 9 0 BA Node Level_2

11 9 1 BB Node Level_2

12 9 2 BC Node Level_2

13 0 2 C Node Level_1

14 13 0 CA Node Level_2

15 13 1 CB Node Level_2

16 13 2 CC Node Level_2

17 13 3 CD Node Level_2










share|improve this question
























  • So when the user copies node 2 into node 16 - node 2's PrID changes from 1 to 16, and all the children of node 2 become children of node 16, or do they stay children of node 2?

    – Zohar Peled
    Nov 15 '18 at 12:15











  • @ZoharPeled I updated the question.

    – eusataf
    Nov 15 '18 at 13:56











  • Well, basically you need to duplicate a record, and then repeat this for all the records associated with it. You might have a problem with the auto-increment columns.

    – Zohar Peled
    Nov 15 '18 at 14:08











  • @Zohar Peled You might have a problem with the auto-increment .. - Are you talking about field ID - autoincrement (formed by the database) .? I made it just by analogy. Are you talking about field ID - autoincrement (formed by the database) .? I made it just by analogy. 1. Option 1. Will it be correct to create an ID in the code? Example: ID-new record = maximum` ID` of table +1. 2. Option 2. Will the scenario be correct: Scenario: 2.0. we copy "parent". 2.1. save the "parent" in the database; 2.2. obtained from the database ID" parent "2.3. assign ID" parent "child entries;

    – eusataf
    Nov 15 '18 at 14:18











  • If the id column is auto-generated by the database, perhaps it's better to do the entire thing in a stored procedure and re-select. There are ways to ensure correctly handling the auto-increment in code, but without knowing what database you are working with, it's impossible to predict how will it handle newly added rows.

    – Zohar Peled
    Nov 15 '18 at 14:22













0












0








0








There is a database table. (MS Access)

On the basis of the table a tree is formed.



field ID - autoincrement (formed by the database).



Scenario:

1. User. Selects the node to copy;

2. User. Selects the node where to copy;

3. Program. Gets the string of the node to be copied;

4. Program. Copies the string "2 1 0 AA Node Level_2" and the associated strings as child lines (nodes) into the node "16 13 2 CC Node Level_2", which is specified as "recipient";

5. Program. Updates the database table based on changes to the DataTable.



Question.

How to programmatically “copy” and “insert” for a specific record of the table (DataTable) and its child nodes (rows) with any nesting of nodes?

The question means how to perform clause 3, clause 4?



As a result, additional records should appear in the source table.
ID // PrID // sorting // NodeName // field_1 // field_2 // field_3

18 16 0 AA Node Level_2

19 18 0 AAA Node Level_3

20 19 0 AAAA Node Level_4

21 19 1 AAAB Node Level_4

23 19 2 AAAC Node Level_4_Изм_3



Tree based on source table
Tree based on source table



public void connect()

string catBD = @"c:testvisualStudiocsharp11.accdb";
string conBD = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=0", catBD);

OleDbConnection connection = new OleDbConnection(conBD);

connection.Open();

string query1 = "SELECT * FROM TableTreeView_12_0";
OleDbCommand cmd1 = new OleDbCommand(query1, connection);


dt = new DataTable();

adapter = new OleDbDataAdapter(cmd1);
cb = new OleDbCommandBuilder(adapter);

adapter.Fill(dt);




Source table
ID // PrID // sorting // NodeName // field_1 // field_2 // field_3

1 0 0 A Node Level_1_изм_2

2 1 0 AA Node Level_2

3 2 0 AAA Node Level_3

4 3 0 AAAA Node Level_4

5 3 1 AAAB Node Level_4

6 3 2 AAAC Node Level_4_Изм_3

7 1 1 AB Node Level_2

8 1 2 AC Node Level_2

9 0 1 B Node Level_1

10 9 0 BA Node Level_2

11 9 1 BB Node Level_2

12 9 2 BC Node Level_2

13 0 2 C Node Level_1

14 13 0 CA Node Level_2

15 13 1 CB Node Level_2

16 13 2 CC Node Level_2

17 13 3 CD Node Level_2










share|improve this question
















There is a database table. (MS Access)

On the basis of the table a tree is formed.



field ID - autoincrement (formed by the database).



Scenario:

1. User. Selects the node to copy;

2. User. Selects the node where to copy;

3. Program. Gets the string of the node to be copied;

4. Program. Copies the string "2 1 0 AA Node Level_2" and the associated strings as child lines (nodes) into the node "16 13 2 CC Node Level_2", which is specified as "recipient";

5. Program. Updates the database table based on changes to the DataTable.



Question.

How to programmatically “copy” and “insert” for a specific record of the table (DataTable) and its child nodes (rows) with any nesting of nodes?

The question means how to perform clause 3, clause 4?



As a result, additional records should appear in the source table.
ID // PrID // sorting // NodeName // field_1 // field_2 // field_3

18 16 0 AA Node Level_2

19 18 0 AAA Node Level_3

20 19 0 AAAA Node Level_4

21 19 1 AAAB Node Level_4

23 19 2 AAAC Node Level_4_Изм_3



Tree based on source table
Tree based on source table



public void connect()

string catBD = @"c:testvisualStudiocsharp11.accdb";
string conBD = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=0", catBD);

OleDbConnection connection = new OleDbConnection(conBD);

connection.Open();

string query1 = "SELECT * FROM TableTreeView_12_0";
OleDbCommand cmd1 = new OleDbCommand(query1, connection);


dt = new DataTable();

adapter = new OleDbDataAdapter(cmd1);
cb = new OleDbCommandBuilder(adapter);

adapter.Fill(dt);




Source table
ID // PrID // sorting // NodeName // field_1 // field_2 // field_3

1 0 0 A Node Level_1_изм_2

2 1 0 AA Node Level_2

3 2 0 AAA Node Level_3

4 3 0 AAAA Node Level_4

5 3 1 AAAB Node Level_4

6 3 2 AAAC Node Level_4_Изм_3

7 1 1 AB Node Level_2

8 1 2 AC Node Level_2

9 0 1 B Node Level_1

10 9 0 BA Node Level_2

11 9 1 BB Node Level_2

12 9 2 BC Node Level_2

13 0 2 C Node Level_1

14 13 0 CA Node Level_2

15 13 1 CB Node Level_2

16 13 2 CC Node Level_2

17 13 3 CD Node Level_2







c# ms-access ado.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 14:27









Zohar Peled

54.1k73373




54.1k73373










asked Nov 14 '18 at 11:12









eusatafeusataf

1039




1039












  • So when the user copies node 2 into node 16 - node 2's PrID changes from 1 to 16, and all the children of node 2 become children of node 16, or do they stay children of node 2?

    – Zohar Peled
    Nov 15 '18 at 12:15











  • @ZoharPeled I updated the question.

    – eusataf
    Nov 15 '18 at 13:56











  • Well, basically you need to duplicate a record, and then repeat this for all the records associated with it. You might have a problem with the auto-increment columns.

    – Zohar Peled
    Nov 15 '18 at 14:08











  • @Zohar Peled You might have a problem with the auto-increment .. - Are you talking about field ID - autoincrement (formed by the database) .? I made it just by analogy. Are you talking about field ID - autoincrement (formed by the database) .? I made it just by analogy. 1. Option 1. Will it be correct to create an ID in the code? Example: ID-new record = maximum` ID` of table +1. 2. Option 2. Will the scenario be correct: Scenario: 2.0. we copy "parent". 2.1. save the "parent" in the database; 2.2. obtained from the database ID" parent "2.3. assign ID" parent "child entries;

    – eusataf
    Nov 15 '18 at 14:18











  • If the id column is auto-generated by the database, perhaps it's better to do the entire thing in a stored procedure and re-select. There are ways to ensure correctly handling the auto-increment in code, but without knowing what database you are working with, it's impossible to predict how will it handle newly added rows.

    – Zohar Peled
    Nov 15 '18 at 14:22

















  • So when the user copies node 2 into node 16 - node 2's PrID changes from 1 to 16, and all the children of node 2 become children of node 16, or do they stay children of node 2?

    – Zohar Peled
    Nov 15 '18 at 12:15











  • @ZoharPeled I updated the question.

    – eusataf
    Nov 15 '18 at 13:56











  • Well, basically you need to duplicate a record, and then repeat this for all the records associated with it. You might have a problem with the auto-increment columns.

    – Zohar Peled
    Nov 15 '18 at 14:08











  • @Zohar Peled You might have a problem with the auto-increment .. - Are you talking about field ID - autoincrement (formed by the database) .? I made it just by analogy. Are you talking about field ID - autoincrement (formed by the database) .? I made it just by analogy. 1. Option 1. Will it be correct to create an ID in the code? Example: ID-new record = maximum` ID` of table +1. 2. Option 2. Will the scenario be correct: Scenario: 2.0. we copy "parent". 2.1. save the "parent" in the database; 2.2. obtained from the database ID" parent "2.3. assign ID" parent "child entries;

    – eusataf
    Nov 15 '18 at 14:18











  • If the id column is auto-generated by the database, perhaps it's better to do the entire thing in a stored procedure and re-select. There are ways to ensure correctly handling the auto-increment in code, but without knowing what database you are working with, it's impossible to predict how will it handle newly added rows.

    – Zohar Peled
    Nov 15 '18 at 14:22
















So when the user copies node 2 into node 16 - node 2's PrID changes from 1 to 16, and all the children of node 2 become children of node 16, or do they stay children of node 2?

– Zohar Peled
Nov 15 '18 at 12:15





So when the user copies node 2 into node 16 - node 2's PrID changes from 1 to 16, and all the children of node 2 become children of node 16, or do they stay children of node 2?

– Zohar Peled
Nov 15 '18 at 12:15













@ZoharPeled I updated the question.

– eusataf
Nov 15 '18 at 13:56





@ZoharPeled I updated the question.

– eusataf
Nov 15 '18 at 13:56













Well, basically you need to duplicate a record, and then repeat this for all the records associated with it. You might have a problem with the auto-increment columns.

– Zohar Peled
Nov 15 '18 at 14:08





Well, basically you need to duplicate a record, and then repeat this for all the records associated with it. You might have a problem with the auto-increment columns.

– Zohar Peled
Nov 15 '18 at 14:08













@Zohar Peled You might have a problem with the auto-increment .. - Are you talking about field ID - autoincrement (formed by the database) .? I made it just by analogy. Are you talking about field ID - autoincrement (formed by the database) .? I made it just by analogy. 1. Option 1. Will it be correct to create an ID in the code? Example: ID-new record = maximum` ID` of table +1. 2. Option 2. Will the scenario be correct: Scenario: 2.0. we copy "parent". 2.1. save the "parent" in the database; 2.2. obtained from the database ID" parent "2.3. assign ID" parent "child entries;

– eusataf
Nov 15 '18 at 14:18





@Zohar Peled You might have a problem with the auto-increment .. - Are you talking about field ID - autoincrement (formed by the database) .? I made it just by analogy. Are you talking about field ID - autoincrement (formed by the database) .? I made it just by analogy. 1. Option 1. Will it be correct to create an ID in the code? Example: ID-new record = maximum` ID` of table +1. 2. Option 2. Will the scenario be correct: Scenario: 2.0. we copy "parent". 2.1. save the "parent" in the database; 2.2. obtained from the database ID" parent "2.3. assign ID" parent "child entries;

– eusataf
Nov 15 '18 at 14:18













If the id column is auto-generated by the database, perhaps it's better to do the entire thing in a stored procedure and re-select. There are ways to ensure correctly handling the auto-increment in code, but without knowing what database you are working with, it's impossible to predict how will it handle newly added rows.

– Zohar Peled
Nov 15 '18 at 14:22





If the id column is auto-generated by the database, perhaps it's better to do the entire thing in a stored procedure and re-select. There are ways to ensure correctly handling the auto-increment in code, but without knowing what database you are working with, it's impossible to predict how will it handle newly added rows.

– Zohar Peled
Nov 15 '18 at 14:22












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298885%2fhow-to-perform-copy-paste-for-a-specific-record-of-the-table-and-its-child%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298885%2fhow-to-perform-copy-paste-for-a-specific-record-of-the-table-and-its-child%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

What does pagestruct do in Eviews?

Dutch intervention in Lombok and Karangasem

Channel Islands