I have created a SQL server with a table that has data in on a server I have local access to. I have also created an "API" on that same server to get the information from the SQL server so it can be read by my angular application.
At the moment, I can read the rows in the SQL server and have them displayed in my angular application, but, I want to be able to update the SQL table from my angular app (through the API).
This is my API (sqlserver.js):
var express = require('express');
var app = express();
var cors = require('cors');
app.use(cors())
app.get('/', function (req, res) {
var sql = require("msnodesqlv8");
// config for your database
var config = "server=servername;Database=dataBaseName;Trusted_Connection=Yes;Driver={SQL Server Native Client 11.0}"
const query = "SELECT * FROM tableName";
// connect to your database
sql.query(config, query, (err, rows) => {
res.send(rows)
});
});
var server = app.listen(3097, function () {
console.log('Server is running..');
});
I want to be able to use the query
const query = "SELECT * from tableName WHERE ID LIKE <inputFromAngular>"
But I am not sure how to get the parameter from angular into the sqlserver.js. (If I can do this then it will lead to updating the SQL Table using SET
In my angular app this is how I am calling the sqlserver.js to display the SQL table:
import { HttpClient } from '@angular/common/http';
constructor(
private httpService: HttpClient
) { }
this.httpService.get("http://servername:3097").subscribe(response => {
console.log(response)
this.sqlData = response;
})
I have tried using this.httpService.post() but I wasn't sure how to get the parameters in the API?