我是 Electron 的新手。
我正在尝试使用 Electron 构建一个小型应用程序。我要做的是插入从前端获取的数据。
我正在使用 SQL 有数据库并作为前端做出反应,可以提供任何建议。
如何插入数据?任何人都可以给我解决方案吗?
请帮我。
我试过这样:这是我的索引 .html,我需要发布从这里获取的数据。在 ZIpcode.js 中,MySQL 代码将在那里。
索引.html
<div>
<form className =" col-lg-12 form-horizontal" role="form" >
<nav className="navbar navbar-inverse navbar-fixed-top">
<div className = "container-fluid">
<div className="navbar-header">
<div className="col-lg-12 col-sm-12 col-xs-12">
<div className ="row">
<div className="col-lg-2 col-sm-2 col-xs-2">
<button type="submit" id="btnSubmit" className="btn btn-primary center-block">
Submit
</button>
</div>
<div className="col-lg-1 col-sm-1 col-xs-1">
<button type="reset" className="btn btn-danger center-block">
Cancel
</button>
</div>
</div>
</div>
</div>
</div>
</nav>
<br/><br/><br/>
<div className ="container">
<div className = "row">
<div className = "row">
<div className="col-lg-6 col-sm-6 col-xs-6">
<div className="form-group">
<div className="col-lg-1 col-sm-1">
</div>
<label className="control-label col-lg-4 col-sm-4 col-xs-12" for="ZipCode">Zip Code:</label>
<div className="col-lg-6 col-sm-6 col-xs-12">
<input type="number" className="form-control" id="ZipCode" ref = "ZipCode" placeholder="Zip Code" required="true"/>
</div>
<div className="col-lg-1 col-sm-1">
</div>
</div>
</div>
<div className="col-lg-6 col-sm-6 col-xs-6">
<div className="form-group">
<label className="control-label col-lg-4 col-sm-4 col-xs-12" for="ShortCode">Short Code:</label>
<div className="col-lg-6 col-sm-6 col-xs-12">
<input type="Short Code" className="form-control" id="ShortCode" ref = "ShortCode" placeholder="Short Code" required="true"/>
</div>
<div className="col-lg-2 col-sm-2">
</div>
</div>
</div>
</div>
<div className = "row">
<div className="col-lg-6 col-sm-6 col-xs-6">
<div className="form-group">
<div className="col-lg-1 col-sm-1">
</div>
<label className="control-label col-lg-4 col-sm-4 col-xs-12" for="City">City:</label>
<div className="col-lg-6 col-sm-6 col-xs-12">
<input type="City" className="form-control" id="City" ref = "City" placeholder="City" required="true"/>
</div>
<div className="col-lg-1 col-sm-1">
</div>
</div>
</div>
<div className="col-lg-6 col-sm-6 col-xs-6">
<div className="form-group">
<label className="control-label col-lg-4 col-sm-4 col-xs-12" for="State">State:</label>
<div className="col-lg-6 col-sm-6 col-xs-12">
<input type="State" className="form-control" id="State" ref = "State" placeholder="State" required="true"/>
</div>
<div className="col-lg-2 col-sm-2">
</div>
</div>
</div>
</div>
<div className = "row">
<div className="col-lg-6 col-sm-6 col-xs-6">
<div className="form-group">
<div className="col-lg-1 col-sm-1">
</div>
<label className="control-label col-lg-4 col-sm-4 col-xs-12" for="PhoneAreaCode">Phone Area Code:</label>
<div className="col-lg-6 col-sm-6 col-xs-12">
<input type="PhoneAreaCode" className="form-control" id="PhoneAreaCode" ref = "PhoneAreaCode" placeholder="Phone Area Code" required="true"/>
</div>
<div className="col-lg-1 col-sm-1">
</div>
</div>
</div>
<div className="col-lg-6 col-sm-6 col-xs-6">
</div>
</div>
<div className = "row">
<div className="col-lg-6 col-sm-6 col-xs-6">
<div className="form-group">
<div className="col-lg-1 col-sm-1">
</div>
<label className="control-label col-lg-4 col-sm-4 col-xs-12" for="TaxCode">Tax Code:</label>
<div className="col-lg-6 col-sm-6 col-xs-12">
<input type="TaxCode" className="form-control" id="TaxCode" ref = "TaxCode" placeholder="Tax Code" required="true"/>
</div>
<div className="col-lg-1 col-sm-1">
</div>
</div>
</div>
<div className="col-lg-6 col-sm-6 col-xs-6">
<div className="form-group">
<label className="control-label col-lg-4 col-sm-4 col-xs-12" for="Tax">%Tax:</label>
<div className="col-lg-6 col-sm-6 col-xs-12">
<input type="number" className="form-control" id="Tax" ref = "Tax" placeholder="Tax" required="true"/>
</div>
<div className="col-lg-2 col-sm-2">
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
邮政编码.js
window.onload = function() {
document.getElementById("btnSubmit").onclick = function () {
alert('Submit button click');
var v1 = document.getElementById('ZipCode').value;
var v2 = document.getElementById('ShortCode').value;
var v3 = document.getElementById('City').value;
var v4 = document.getElementById('State').value;
var v5 = document.getElementById('PhoneAreaCode').value;
var v6 = document.getElementById('TaxCode').value;
var v7 = document.getElementById('Tax').value;
//alert("ZipCode:"+v1+" "+"ShortCode:"+v2+" "+"City:"+v3)
//sql connection
//alert('after Connection');
var Connection = require('tedious').Connection;
var config = {
userName: 'xx',
password: 'xxxx',
server: 'xxxxxx', // You can use 'localhost\\instance' to connect to named instance
database: 'XXXXX',
options: {
database: 'XXXXX'
},
}
alert("SQL")
var connection = new Connection(config);
connection.on('connect',function(err){
alert('hai')
if(err){
console.log(err)
}
executeStatement();
});
Request = require('tedious').Request;
function executeStatement(){
//alert(v1,v2,v3,v4,v5,v6,v7)
var request = new Request("INSERT INTO XXXXX VALUES ("+v1+",'"+v2+"','"+v3+"','"+v4+"','"+v5+"','"+v6+"',"+v7+")",
function(err,result){
console.log(request)
if(err){
console.log(err);
}else{
console.log(result)
}
});
connection.execSql(request);
}
alert('completion')
}
}