If Database doesn't Exist Create it,how?

Hi team!

In my project i Conect Xojo to my SQL Database with this code. Everything goes ok, But I want to say it, If “Facturacion” database doesn’t exist then create it and use it and set names to UTF8:

’ Charging MySQL database
app.mdb = New MySQLCommunityServer

app.mDb.Host = “localhost”
app.mDb.UserName = “root”
app.mDb.Password = “mypassword”

//If mySQL connects successfully then.
If app.mDb.Connect Then
//Use “Facturacin” database

app.mDb.SQLExecute("use facturacion")
//Set UTF8 type characters
app.mDb.SQLExecute ("SET NAMES 'utf8'")

if app.mDb.Error then

//If “Facturacion” database doesn’t exist,then create it
app.mDb.SQLExecute(“CREATE DATABASE facturacion”)
app.mDb.SQLExecute(“use facturacion”)
//Set UTF8 type characters
app.mDb.SQLExecute (“SET NAMES ‘utf8’”)

But It show me a Messagebox: “No table Seelected”

Any Suggestions?

Sorry for the Question, I solve it using this, after “USE”:

app.mDb.SQLExecute(“CREATE DATABASE IF NOT EXISTS facturacion”)

The problem with your original code is the command

app.mDb.SQLExecute ("SET NAMES 'utf8'")

resets the error flag and masks the error returned by

app.mDb.SQLExecute("use facturacion")

If you check for the error immediately after “use facturacion”, you can tell that the database does not exist and create it and its tables. Create if not exists is ok, but your code could be much more intelligent about what it’s doing if you test for app.mDb.Error at the right time.