Transfer Data out of one Table to another

JOTHA

Well-Known Member
Licensed User
Longtime User
Hi Forum,

i have a little problem, maybe some one can help me.

I want to transfer data out of one table to another table.

To explain the problem, here is an example:

1) Table1 stores apples and peaches.

I want to filter in Table1 all peaches and show them (this works fine), but I want to transfer the peaches into another table (= table2). At the end, there should be 2 tables. Table1 with apples and table2 with peaches.

Mabe the way is like this:

  1. open table1
  2. show all rows with peaches
  3. copy all rows with peaches
  4. delete all rows with peaches from table1
  5. save table1 (without peaches)
  6. open table2
  7. copy all rows with peaches to table2
  8. save table 2 (with peaches)

Ready!

But how can I do that? :confused:

2) ... and then it gets a little more difficult:

Lets say in table1 there are 5 peaches.
3 peaches should be transferred to table2.

The result should be 2 tables:
Table1 with 2 peaches left.
Table2 with 3 peaches added.

Can anyone give me tipps?

THANK YOU in Advance!
 
Last edited:

JOTHA

Well-Known Member
Licensed User
Longtime User
Hello Ariel,

thank you for your answer.

How are you implementing the tables? Are these SQL database tables? Do you mean a table control?

No, these tables are not SQL-Tables.
They are table controls.
 

Ariel_Z

Active Member
Licensed User
Please look at this offered solution. It may be about what you need, I think.

B4X:
Sub App_Start
   Form1.Show
   
   ' add some data so it roughly matches the question
   table1.AddCol(cString, "Type", 50)
   table1.AddRow("peach1")
   table1.AddRow("peach2")
   table1.AddRow("apple3")
   table1.AddRow("peach4")
   table1.AddRow("apple5")
   
   table2.AddCol(cString, "Type", 50)
   table2.AddRow("apple6")
   table2.AddRow("apple7")
   table2.AddRow("apple8")
   table2.AddRow("apple9")
   table2.AddRow("apple10")
   
   'filter only what you need. See the help for the filter under table.
   table1.Filter = "Type LIKE 'apple*'"
   
   'add what you need to table2 and take it out of table1
   For i = 0 To table1.RowCount - 1
      table2.AddRow(table1.Cell("Type", 0))
      table1.RemoveRow(0)    ' allways move the first row, because when removing it the second one becomes the first
   Next
   
   'cancel filter
   table1.Filter = ""

End Sub
 

JOTHA

Well-Known Member
Licensed User
Longtime User
Hello Ariel,

thank you for your fast answer.

This part of code was what I am searching for:
'add what you need to table2 and take it out of table1
For i = 0 To table1.RowCount - 1
table2.AddRow(table1.Cell("Type", 0))
table1.RemoveRow(0) ' allways move the first row, because when removing it the second one becomes the first
Next

'cancel filter
table1.Filter = ""

Thank you very much for that help!

But now I have an additional (little) problem.

I want to transfer more than one column.

The table has data in more than one column and I want to transfer the whole rows. The key to do that is

table2.AddRow(table1.Cell("Type", 0))
But what about the table has 5 columns?

Is it ...

table2.AddRow(table1.Cell("Type1", 0))
table2.AddRow(table1.Cell("Type2", 1))
table2.AddRow(table1.Cell("Type3", 2))
table2.AddRow(table1.Cell("Type4", 3))
table2.AddRow(table1.Cell("Type5", 4))

... it doesnt work ...:confused: It only fills the first column!

Thank you again in advantage!
 
Last edited:

specci48

Well-Known Member
Licensed User
Longtime User
Hi JOTHA,

if there are five columns (Type1 to Type 5) you have to

B4X:
table2.AddRow(table1.Cell("Type1", 0), table1.Cell("Type2", 0), table1.Cell("Type3", 0), table1.Cell("Type4", 0), table1.Cell("Type5", 0))


specci48
 

JOTHA

Well-Known Member
Licensed User
Longtime User
Hi specci48,

Hi JOTHA,

if there are five columns (Type1 to Type 5) you have to

B4X:
table2.AddRow(table1.Cell("Type1", 0), table1.Cell("Type2", 0), table1.Cell("Type3", 0), table1.Cell("Type4", 0), table1.Cell("Type5", 0))


specci48

Thank YOU very much!

What should I do without this forum? :)
 
Top