Answer the question
In order to leave comments, you need to log in
How to display a table from sql server using tedious and ejs(node js)?
I use Tedious to connect to sql server. The connection is working.
function queryDatabase() {
request = new Request("SELECT * FROM officers", function (err, rowCount, rows) {
console.log(rowCount + ' row(s) returned');
//process.exit();
});
request.on('row', function (columns) {
columns.forEach(function (column) {
console.log("%s\t%s", column.metadata.colName, column.value);
colOfficer.push(column.metadata.colName);
valOfficer.push(column.value);
});
});
connection.execSql(request);
}
Answer the question
In order to leave comments, you need to log in
Here is a function that allows you to fill the object driver{}
var driver = {};//создал объект
function queryDatabase() {
request = new Request("SELECT * FROM [driving license] WHERE name_driver='Олег'", function (err, rowCount, rows) {
console.log(rowCount + ' row(s) returned');
//process.exit();
});
request.on('row', function (columns) {
columns.forEach(function (column) {
console.log("%s\t%s", column.metadata.colName, column.value);
driver[column.metadata.colName] = column.value;//заполнение объекта
});
});
connection.execSql(request);
}
ar connection = new Connection(config);
connection.on('connect', function (err) {
if (err) {
console.log(err);
}
else {
queryDatabase(); //вот тут юзаем нашу функцию
}
}
)
app.get('/driver', function (req, res) {
res.render('driver', {name:driver.name_driver, lastName:driver.last_name_driver, numPtc:driver.num_ptc, numLicense:driver.num_license});
});
<div class="header">
<h1>Вы зашли как водитель: <%=name%></h1>
<a href="http://localhost:3000/"><div class="btn-close">ВЫХОД</div></a>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question