copy specific table from one location to another

Discussion in 'Questions (Windows Mobile)' started by mozaharul, Jul 1, 2009.

  1. mozaharul

    mozaharul Active Member Licensed User

    Hi,

    I've same database in "My document" as well on SD card. Is it possible to copy a specific table from the "My document" to SD card database ?
    If possible, then how ?


    regards,
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    These are SQL databases? How large are the tables?

    You can create two set of connection objects, command objects and reader objects.
    One set for each database.
    Then read the data row by row and add it to the target database.

    You can also read the complete table with cmd.ExecuteTable and then save it with Connection.createSQLTable.
     
  3. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Another option might be to use SQLite's ATTACH DATABASE:
    SQLite Query Language: ATTACH DATABASE

    Not sure it will work in this specific situation, but the nice thing is that all can be done with one SQL statement, so it will be faster as you don't have to move data to the data reader and then back to another SQLite table.
    Something like this:

    INSERT INTO TABLE1 SELECT * FROM TABLE2


    RBS
     
  4. mozaharul

    mozaharul Active Member Licensed User

    Hi,
    Yes, SQLite database with around 20 tables. The initial size is small but will increase by time, as it is the part of a surveillance database which is updated quarterly in a year.

    "You can create two set of connection objects, command objects and reader objects.
    One set for each database.
    Then read the data row by row and add it to the target database."


    I have done it in the same way with insertion (for new rows) and update (for existing rows) option and its working fine. The purpose is to backup only the tables being changed depending upon a flag. I was looking is there any other smart way.

    "You can also read the complete table with cmd.ExecuteTable and then save it with Connection.createSQLTable."



    For The 2nd option I tried like:

    If btnclose.Text = "Backup" Then
    cmd.CommandText = "select * from rf_disease"
    cmd.ExecuteTable("table5",0)
    ' con1.Open("data source =\SD card\kdss_db" )
    con1.Open("data source =C:\Documents AND Settings\mozaharul\Desktop\test")
    cmd1.CommandText = "drop table rf_disease"
    cmd1.ExecuteNonQuery
    con1.CreateSQLTable("table5","rf_disease")
    Msgbox("Data saved in the SD card")
    con1.Close
    End If

    It works fine but the problem is that, for all numeric field, the data type is changed to real one. How to preserve the data type of the target table intact ?


    regards,
     
    Last edited: Jul 2, 2009
  5. Erel

    Erel Administrator Staff Member Licensed User

    You will not be able to preserve the original data type. Tables store all numbers as doubles.
    RBS suggestion looks like a better solution in your case.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice