1

I'm creating a c# console app and using sqlite as my db, and I have two scripts the first script (DBCreationScript.sql) contains the database schema(tables to be created) and the second script (DefaultData.sql) populates the database tables with default data. Is there a way or specific code that I could use to load/import/run the two scripts in my console application.

My goal is to : 1. Create the sqlite db (by loading the script) using code from my console app. 2. Populate the database (by loading the second script). 3. Then query the data and display on the console screen

see below the two scripts.

CREATE TABLE tbLocation
(
    LocationCd			varchar(3)	PRIMARY KEY
    ,LocationName		varchar(50)
    ,CountryCd			varchar(2)	REFERENCES tbCountry(CountryCd)
    ,CountryName        varchar(25)
    ,PassportRequired	bit
    ,SortOrder			Integer
);

CREATE TABLE tbManage
(
    ConfigParamCd		varchar(25)	PRIMARY KEY
    ,ConfigParamDesc	varchar(225)
    ,ConfigParamTypeCd	varchar(20)
    ,Value				varchar(2000)
    ,[Status]			bit
);

CREATE TABLE tbPerson
(
    PersonNo					varchar(10)	PRIMARY KEY
    ,FirstName			varchar(25)
    ,LastName			varchar(25)
    ,PinCode			varchar(5)
    ,FleetCd			varchar(10)
    ,[Status]			bit
);

.

INSERT INTO tbManage (ConfigParamCd,ConfigParamDesc,ConfigParamTypeCd,Value,Status)
select 'AirlineCd' ConfigParamCd, 'The current airline code.' ConfigParamDesc, 'String' ConfigParamTypeCd, 'BA' Value, '1' Status UNION
select 'CanCreateNewSector' ConfigParamCd, 'Does this airline allow crew members to create new sectors?' ConfigParamDesc, 'Boolean' ConfigParamTypeCd, '1' Value, '1' Status UNION
select 'CanEditSeals' ConfigParamCd, 'Does this airline allow crew members to add, edit or delete seals?' ConfigParamDesc, 'Boolean' ConfigParamTypeCd, '1' Value, '1' Status UNION
select 'CanSectorsReopen' ConfigParamCd, 'Does this airline allow crew members to reopen sectors?' ConfigParamDesc, 'Boolean' ConfigParamTypeCd, '1' Value, '1' Status UNION
select 'DefaultCurrency' ConfigParamCd, 'The default currency code.' ConfigParamDesc, 'String' ConfigParamTypeCd, 'ZAR' Value, '1' Status UNION
select 'DefaultCurrencySymbol' ConfigParamCd, 'The default currency symbol.' ConfigParamDesc, 'String' ConfigParamTypeCd, 'R' Value, '1' Status UNION
select 'EmergencyNumber' ConfigParamCd, 'The emergency number of the airline.' ConfigParamDesc, 'String' ConfigParamTypeCd, '911' Value, '1' Status UNION

1 Answer 1

1

You should create a db script consisting of DDL and DML first and call, SQLiteConnection.CreateFile(string databaseFileName) method. Specify IF NOT EXISTS in the CREATE statement.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks!!! I have used SQLiteConnection.CreateFile(DBCreationpath) where the path represented the relative path of the Sqlite db. and it worked :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.