Danish Habib

Danish Habib

  • NA
  • 694
  • 245.9k

I want to save data into sql server table using javascript

Nov 24 2015 12:50 PM
I have html page i want to save data into the sql table using javascript below is my code but my data is not saving i am not getting any exception , how to check weather the connection is working properly or not 
----------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" >
function ShowAll()
{
var connection = new ActiveXObject("ADODB.Connection");
var connectionstring = "Data Source=ASPKCO-DANISH\SQLEXPRESS;Initial Catalog=Sample;Persist Security=SSPI;Provider=SQLOLEDB";
connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");
rs.Open("select * from Emp_Info ", connection);
if (rs.Open()) {
alert('Connection is open');
}
rs.MoveFirst();
var span = document.createElement("span");
span.style.color = "Blue";
span.innerText = " ID " + " Name " + " Salary" + " City ";
document.body.appendChild(span);
while (!rs.eof)
{
var span = document.createElement("span");
span.style.color = "green";
span.innerText = "\n " + rs.fields(0) + " | " + rs.fields(1) + " | " + rs.fields(2) + " | " + rs.fields(3);
document.body.appendChild(span);
rs.MoveNext();
}
rs.close();
connection.close();
}
</script>
</head>
<body style="height: 431px">
<div id="show"
style="font-size: x-large; font-weight: bold; height: 298px; color: #009999;">
Insert Employee Record<p style=" color: #000000;">
Employee Id&nbsp;&nbsp;
<input id="txtid" type="text" /></p>
<p style=" color: #000000;">
Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input id="txtname" type="text" /></p>
<p style=" color: #000000;">
Salary&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input id="txtsalary" type="text" /></p>
<p style=" color: #000000;">
City&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input id="txtcity" type="text" /></p>
<input id="ShowRecord" type="button" value="Insert" onclick="InsertRecord()" />&nbsp;
<input id="showall" type="button" value="Show All Record" onclick="ShowAll()" /></div>
</body>
</html>
---------------------
My table contains
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Emp_Info](
[Emp_Id] [int] NOT NULL,
[Name] [nvarchar](50) NULL,
[Salary] [int] NULL,
[City] [nvarchar](50) NULL,
CONSTRAINT [PK_Emp_Info] PRIMARY KEY CLUSTERED
(
[Emp_Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
 
 

Answers (1)