hamze torabzade
hamze torabzade

Reputation: 7311

Insert the value of a JavaScript function to an SQL Server database

Is it possible to add a JavaScript variable in an SQL Server database database (run an SQL query or stored procedure)? If so, how?

Upvotes: 0

Views: 3099

Answers (5)

kop48
kop48

Reputation: 495

You can easily access a database from JavaScript in Node.js.

If you're doing it from the browser, you'll most definitely need some kind of mid-tier service which translates HTTP queries to the relevant database driver (you can write that in any language you want - PHP, JavaScript, ASP.NET, etc.).

Upvotes: 0

M.R.
M.R.

Reputation: 4827

You can use Ajax to post to a web service of some sort (or any other server side script) to pass the JavaScript value. The web service would access the database and save it...

Upvotes: 1

Naren Sisodiya
Naren Sisodiya

Reputation: 7288

You can not access the database from JavaScript. You need to send your data to PHP, Ruby on Rails or ASP.NET or whatever you are using to implement the back end.

Upvotes: 1

Dominic Barnes
Dominic Barnes

Reputation: 28429

With JavaScript only, no you cannot (unless you're using Node.js of course).

The point is, you'll need some server-side code to interact with your database. You can use JavaScript in the browser to make an Ajax call to a server-side script (PHP, Ruby, Python, ASP.NET, Node.js, etc.) that performs the interaction with the database.

Upvotes: 4

Govind Malviya
Govind Malviya

Reputation: 13753

Set value of variable in the hidden field and get value of that field at server side when submit form and save it into the database....

Upvotes: 0

Related Questions