0

I have set of JSON data, which can be seen in the console.log coming from Javascript, in console looks like this:

0: {datum: "18:17:00 04.08.2020", winddir: "S", windspeed: "28.7", windgust: "27.8", temp: "17.2"}
1: {datum: "18:16:00 04.08.2020", winddir: "NW", windspeed: "51.5", windgust: "32.9", temp: "17.2"}
2: {datum: "18:15:00 04.08.2020", winddir: "N", windspeed: "52.5", windgust: "32.2", temp: "17.3"}
3: {datum: "18:14:00 04.08.2020", winddir: "W", windspeed: "38.8", windgust: "28.4", temp: "17.3"}
4: {datum: "18:13:00 04.08.2020", winddir: "NW", windspeed: "30.2", windgust: "36.3", temp: "17.2"}
5: {datum: "18:12:00 04.08.2020", winddir: "N", windspeed: "31.6", windgust: "29.5", temp: "17.3"}

This is the javascript that generates the JSON data:

<script type="text/javascript">

var table = document.getElementById("weather");
var tableArr = [];
for (var i = 1; i < 100; i++) {
    tableArr.push({
        datum: table.rows[i].cells[0].innerHTML,
        winddir: table.rows[i].cells[1].innerHTML,
        windspeed: table.rows[i].cells[2].innerHTML,
        windgust: table.rows[i].cells[6].innerHTML,
        temp: table.rows[i].cells[8].innerHTML,
        tempchill: table.rows[i].cells[9].innerHTML
    });
}
console.log(tableArr);
</script>

This is all good, but now I want to insert these into MSSQL database with below vbscript asp call:

Set ObjRS = Server.CreateObject("ADODB.Recordset")
    SQL="DECLARE @json nvarchar(max) set @json ="& tableArr &" Select * FROM OPENJSON(@json) WITH (datum datetime, winddir nvarchar(50), windspeed decimal(10,2), windgust decimal(10,2), temp decimal(10,2), tempchill decimal (10,2))"
    Response.Write(SQL)
    ObjRS.Open SQL, ObjDb, adOpenStatic, adLockReadOnly

When I print SQL call into HTML this "& tableArr &" is empty, thus SQL call fails. This SQL call is just to see the data in HTML, but if this works then I will directly insert it into DB.

Thanks for all the hints!! Martin

  • 2
    Declaring an array in javascript doesn't make it available to your page's code-behind if that's what you're trying to do. How are you passing `tableArr` to your ADODB code? – critical_error Aug 04 '20 at 20:23
  • Yes, I found its not possible to pass array to ADODB code this way. What other options do I have? How to call javascript array into ADODB code? – Martin Madara Aug 04 '20 at 20:26

0 Answers0