Do I simply use my code above just to create the database and column, and then have to connect to it and populate the column with 2 entries, as per usual - OR - can the column actually be populated at creation time, in the same line of code above?
I need to add 2 entries to the column, and was hoping that I could modify my line of code above to populate the column at creation time (as opposed to having to connect and then populate etc.).
Create a string constant that is ALL the sql you need to create & populate the DB initially
You can create this by hand to make sure it all works
Then just do something like
dim lines() as string = Split( replacelineendings(constant, endofline), endofline )
for each line as string in lines
mydb.SQLExecute( line )
next
this is one of the VERY few places where I might skip error checking because if you have an error in your initial set up & data load that you missed in testing well … public flogging
Tim - thanks.
Your syntax needed correcting slightly though:
Dim ps As SQLitePreparedStatement = IncidentsDB.Prepare("INSERT INTO Types (Type) VALUES (?);")
ps.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
ps.SQLExecute("val1")
ps.SQLExecute("val2")
Norman,
Your code is a bit too advanced for me at the moment - but thank you anyway
Will try your method Norman.
Have I put the code in the right place??? I have never used string constants before, and have added one as advised, but was not sure where to stick the code?
Jym,
I’m not using numbers - each value will be a text string. Norman just used numbers as an example, and I will be changing them to strings as soon as I know the code is in the right place.
[quote=130688:@Richard Summers]Will try your method Norman.
Have I put the code in the right place??? I have never used string constants before, and have added one as advised, but was not sure where to stick the code?
[/quote]
The code goes wherever you want and gets called from where it is you are deciding you need to create the database (presumably because a preexisting one does not exist)
What I meant was - is my code in the right place i.e. - in the Edit Value area.
It is now all sorted and working perfectly - thank you very much Norman - much appreciated
Personally I’d make the column UNIQUE and add a PRIMARY KEY column because it’s much easier to organize a numbered column then it is to organize text column.
i.e.
CREATE TABLE mytable
(
mytext NOT TEXT NULL UNIQUE, myIPK INTEGER PRIMARY KEY
)
but I think you said you were using mySQL which is a little different
CREATE TABLE mytable
(
mytext TEXT NOT NULL, myIPK INTEGER NOT NULL,
CONSTRAINT on_mytable UNIQUE (mytext, myIPK)
)