Android Question Sqlite /SQL Server

Pilar-JLSineriz

Active Member
Licensed User
Longtime User
Hello,

I am making an APK that works with a database SQLITE. I want to design a button in the APK that transform the SQLITE file in a SQL file that can be to read by SQL Server.

For example, I am taking data about the properties of the different mineral waters and the data are stored in a SQLITe database, but I want that the database can be read in SQL Server. I want to put a button in the APK so that when the user finishs to take data, push the bottom and the APK generates a SQL file with the mineral waters data, that the user can be to send it by email or copy in a pen-drive so after it can be copied in the Server and it can be read with SQL Server.

Many thanks
 

cimperia

Active Member
Licensed User
Longtime User
There are a few ways to do just that.

Here is a simple implementation based on SQL Server CSV Import.

First generate a CSV file from your app and then import it into your SQLSERVER database.

To handle rows which aren't loaded into the table because of invalid data or format, could be handle using ERRORFILE property, specify the error file name, it will write the rows having error to error file. code could look like.

B4X:
BULK INSERT MineralWaterTable
  FROM 'C:\CSVData\mineralWaters.csv'
  WITH
  (
  FIRSTROW = 2,
  FIELDTERMINATOR = ',',  --CSV field delimiter
  ROWTERMINATOR = '\n',  --Use to shift the control to next row
  ERRORFILE = 'C:\CSVData\mineralWatersErrorRows.csv',
  TABLOCK
  )
 
Upvote 0

Pilar-JLSineriz

Active Member
Licensed User
Longtime User
There are a few ways to do just that.

Here is a simple implementation based on SQL Server CSV Import.

First generate a CSV file from your app and then import it into your SQLSERVER database.

To handle rows which aren't loaded into the table because of invalid data or format, could be handle using ERRORFILE property, specify the error file name, it will write the rows having error to error file. code could look like.

B4X:
BULK INSERT MineralWaterTable
  FROM 'C:\CSVData\mineralWaters.csv'
  WITH
  (
  FIRSTROW = 2,
  FIELDTERMINATOR = ',',  --CSV field delimiter
  ROWTERMINATOR = '\n',  --Use to shift the control to next row
  ERRORFILE = 'C:\CSVData\mineralWatersErrorRows.csv',
  TABLOCK
  )


Thanks.. I am going to try with this but I don´t know if I have success.. what happen when the DB has more tables than one? Have I repeat the instruction several times? Moreover, my initial file is SQLite not csv
 
Upvote 0
Top