Avatar of Whing Dela Cruz
Whing Dela Cruz
Flag for Anguilla asked on

How to create Web sql using var declaraion?

Hi, experts how to correct this code? I declare S1 = Mytable. when excecute the code below S1 would be the result. I want the result would be Mytable.

    function create()
    {
        var S1 = "MyTable";
        db.transaction(function (tx)
        {
            tx.executeSql('CREATE TABLE IF NOT EXISTS S1 (s_id INTEGER PRIMARY KEY ASC, id unique, firstName, familyName)');
        });
        alert("Successfully created!");
    }
Microsoft SQL ServerHTMLJavaScript

Avatar of undefined
Last Comment
PortletPaul

8/22/2022 - Mon
SOLUTION
PortletPaul

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
chaau

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Whing Dela Cruz

ASKER
Hi Paul Maxwell, the code above is already working on my pc. The only thing I need is that to replace "MyTable" into S1 since S1 was already declared as MyTable. There's no problem if make the code like this;
 
tx.executeSql('CREATE TABLE IF NOT EXISTS Mytable (s_id INTEGER PRIMARY KEY ASC, id unique, firstName, familyName)');

the thing I need is how to make the statement that would replace Mytable to S1 since S1 is variable. It is possible? thanks!
Whing Dela Cruz

ASKER
Hi chaau, your perfectly right! thanks both of you. God Bless!
Whing Dela Cruz

ASKER
Thanks Paul for reminding me!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
PortletPaul

no problem, it's all part of the service :)