/    Sign up×
Community /Pin to ProfileBookmark

using javascript to perform SQL in an aspx page

Hello,
I am relatively new to jscript.
I have an aspx page.
I use a recordset.addnew() to add data to a SQL Table. Ive tried this with an jscript executed select or insert command. This works fine. The data gets entered into the table.

Where I have been having extreme difficulties is in calling upon the IDENTITY value of the inserted data in the SQL table.

[B]var sql1 = “INSERT INTO Table (LI, LoI) VALUES(‘” + yco + “‘, ‘” + xco + “‘) SELECT @@IDENTITY”;
var result1 = connection.Execute(sql1);
newID3 = result1.Fields(0).value; [/B]

—– This does not return any value, let alone the intended value. So I tried a different approach to find the ID value of the inserted data.

[B]var connection;
connection = Server.CreateObject(“ADODB.Connection”);

connection.Open(“Provider=SQLOLEDB;Data Source=tcp:127.0.0.1,1433;Initial Catalog=Outside;Integrated Security=SSPI;”)

var status = “Can’t access table.”;

// create recordset

var rsQuery = Server.CreateObject(“ADODB.Recordset”);
rsQuery.CursorType = adOpenKeyset;
rsQuery.LockType = adLockOptimistic;

var SQL = “Select idnum AS ID From FishTable Where (LI = ‘” + yco + “‘) AND (LoI = ‘” + xco + “‘)”;
var ID2 = rsQuery.Open(“Select idnum AS ID From FishTable Where (LI = ‘” + yco + “‘) AND (LoI = ‘” + xco + “‘)”,connection);
var ID3 = ID2.Fields(“ID”).value;

LI and LoI get successfully entered into the table using :

[CENTER]

recordset.AddNew();

recordset.Fields(“LongitudeI”).Value = xco;
recordset.Fields(“LatitudeI”).Value = yco;[/B]

With this way I tried to select the named IDENTITY column (“idnum”) based on the LI, and LoI values that were entered in the table (SELECT FROM WHERE).

All I wish to be able to do is enter the data into a table and call the ID value of this entered data to enable future data access to the same table entry that the LI and LoI values get entered into.

Ugh. Im so confused, Im not sure if any of this makes sense.

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @scotthiggins spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...