Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
Down is my code to list the names of a particular customer from a table selecting the active project from the project table.

C#
function addTable() {

    var myTableDiv = document.getElementById("myDynamicTable");
    var table = document.createElement('TABLE');
    table.border='1';

    var tableBody = document.createElement('TBODY');
    table.appendChild(tableBody);
  db.transaction(function(transaction)
    {
    
     var pro=localStorage.getItem("ActiveProject");
     var activePro='Select Prjdb_id from ProjectTable where Proj_name="'+pro+'" ';
    transaction.executeSql(activePro , [],  function(transaction, result)
    {
             for (var i = 0; i <  result.rows.length; i++)
             {
                var row = result.rows.item(i);
                    id=row.Prjdb_id;
             }
               db=openDatabase(id, version, displayName,maxSize);
      if(id)
         {
          transaction.executeSql('SELECT * FROM customer' , [],  function(transaction, result)
          {
         
            le=result.rows.length;
            if (result.rows.length != 0)
            {
            var row = result.rows.item(i);
            var name= row.Cust_name;
            for(var i=0;i<2;i++)
            {
            var tr = document.createElement('TR');
            tableBody.appendChild(tr);
            for (var j=0; j<le; j++)
            {
            var td = document.createElement('TD');
            td.width='75';
            td.appendChild(document.createTextNode(name));
            tr.appendChild(td);
            }
            }
            myTableDiv.appendChild(table);
            }
          },errorHandler);
         }
    });
 });



C#
function errorHandler(tx, error)
{
  alert("Database Error: " + error);
}


It goes well till the if(id) condition inside the condition it opens the database too.But doesnot enter the next line of executing the sql command.
Can anybody please help me...
Posted
Updated 6-May-14 18:24pm
v4
Comments
Do you see any errors on Console Tab of Developer window?
p@y@l 7-May-14 4:32am    
No errors displayed.Also,I have inserted an alert after this statement-transaction.executeSql('SELECT * FROM customer' , [], function(transaction, result)
and checked,the alert is not displayed.
I have checked out this too..
after adding the errorHandler() (changes done in code) i get the error Database Error:[ObjectSQLError]
Are you sure that this local Database exists at client side?
p@y@l 8-May-14 2:06am    
Yes it exists,i have created and inserted to the database tables.
p@y@l 8-May-14 4:17am    
Thanks for your interest for help.I got the solution.:)

1 solution

JavaScript
db1 = openDatabase(id, version, displayName,maxSize);

db1.transaction(function(transaction)
{ 
    //ur code here 
});


Inside the code make changes as the above.
Since there are two databases used here the first one is Main database and the second is Project database second db should has a different name.

This worked well for me..


[Edit member="Tadit"]
Corrected formatting issues.
Added pre tags.
[/Edit]
 
Share this answer
 
v4
Comments
Take 5 Stars for solving it yourself. :)
Keep it up. :)

Thanks,
Tadit
p@y@l 9-May-14 5:52am    
Thank you :)
Welcome. :)
p@y@l 9-May-14 7:38am    
I have asked one more question,if u can please help.
Ok. I am checking... :) Thanks for informing. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900