Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
<head>
    <title></title>
    <script language="javascript" type="text/javascript" >
        function InsertRecord()
        {
            var txtid = document.getElementById('txtid').value;
            var txtname = document.getElementById('txtname').value;
            var txtsalary = document.getElementById('txtsalary').value;
            var txtcity = document.getElementById('txtcity').value;
            if (txtid.length != 0 || txtname.length !=0 || txtsalary.length !=0|| txtcity.length !=0)
            {
                var connection = new ActiveXObject("ADODB.Connection");
                var connectionstring = "Data Source=RTSIND018\sqlexpress;Initial Catalog=AliDB;User ID=sa;Password=***";
                connection.Open(connectionstring);
                var rs = new ActiveXObject("ADODB.Recordset");
                rs.Open("insert into Emp_Info values('" + txtid + "','" + txtname + "','" + txtsalary + "','" + txtcity + "')", connection);
                alert("Insert Record Successfuly");
                txtid.value = " ";
                connection.close();
            }
            else
            {
                alert("Please Enter Employee \n Id \n Name \n Salary \n City ");
            }
        }
        function ShowAll()
        {
                var connection = new ActiveXObject("ADODB.Connection");
                var connectionstring = "Data Source=RTSIND018\sqlexpress;Initial Catalog=AliDB;User ID=sa;Password=***";
                connection.Open(connectionstring);
                var rs = new ActiveXObject("ADODB.Recordset");
                rs.Open("select * from Emp_Info ", connection);
                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>
<body>
 <input id="txtid" type="text" /></p>
        <p style="font-size: medium; color: #000000;">
            Name
            <input id="txtname" type="text" /></p>
        <p style="font-size: medium; color: #000000;">
            Salary
            <input id="txtsalary" type="text" /></p>
        <p style="font-size: medium; color: #000000;">
            City
            <input id="txtcity" type="text" /></p>
 <input id="ShowRecord" type="button" value="Insert" onclick="InsertRecord()" />
    <input id="showall" type="button" value="Show All Record" onclick="ShowAll()" /></div>
      </body>
</html>
Posted
Updated 17-Jun-14 22:24pm
v2
Comments
Kornfeld Eliyahu Peter 18-Jun-14 4:50am    
Do you have an error? Please share with us!
Member 10532069 18-Jun-14 6:20am    
Hi,
there is no error
But When I click on insert button the page is not loading as well as not inserting the data into db
Kornfeld Eliyahu Peter 18-Jun-14 6:23am    
Maybe no error displayed...check with the browsers debugger he console messages...

1 solution

In Your Connection String You Cannot Specified Any Provider. Try This

var connectionstring = "Data Source=RTSIND018\sqlexpress;Initial Catalog=AliDB;User ID=sa;Password=***";Provider=SQLOLEDB;";

Run your code using Internet explorer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900