Wednesday, 26 April 2017

Fetch Data from SQL Database in Apache Cordova

I was trying to fetch data from SQL database by following the steps in this link > https://docs.microsoft.com/en-us/azure/sql-database/sql-database-connect-query-nodejs. I have face problem displaying the data in table in my mobile application..i am new to apache cordova so please give some advises on how to fetch data from the database

 var Connection = require('tedious').Connection;
             var Request = require('tedious').Request;

             var config =
             {
                 userName: 'sa',  
                 password: 'Admin123',  
                 server: 'USERWIN10\SQLEXPRESS',  
                 // If you are on Azure SQL Database, you need these next options.  
                 options: {database: 'HR'}  
             };

             var connection = new Connection(config);
             connection.on('connect', function (err) {
                 // If no error, then good to proceed
                 console.log("Connected");
                 executeStatement();
             });

             var Request = require('tedious').Request;
             var TYPES = require('tedious').TYPES;

             function queryDatabase() {
                 // Read all rows from table
                 request = new Request("SELECT * FROM dbo.USERTBL;", function (err) {
                         console.log(rowCount + ' row(s) returned');
                     }
                 );

                 request.on('row', function (columns) {
                     columns.forEach(function (column) {
                         console.log("%s\t%s", column.metadata.colName, column.value);
                     });
                 });

                 connection.execSql(request);
             }



via jarkwt

No comments:

Post a Comment