日期:2014-05-16  浏览次数:20430 次

javascript连接数据库
IE的连接会了

        function connSql() {
            var conn = new window.ActiveXObject("adodb.connection");
            var dr = new window.ActiveXObject("ADODB.Recordset");
            conn.ConnectionString = "Provider=SQLOLEDB.1;User ID=sa;Password=123456;Initial Catalog=ERP;Data Source=.";
            conn.open;
            var sql = "select * from user_info";
            dr.open(sql, conn);
            shtml = "<table width='100%' border=1>";
            shtml += "<tr>";
            for (var i = 0; i < dr.Fields.count; i++) {
                shtml += "<td>" + dr.Fields(i).name + "</td>";
            }
            shtml += "</tr>";

            while (!dr.EOF) {
                shtml += "<tr>";
                for (var i = 0; i < dr.Fields.count; i++) {
                    shtml += "<td>" + dr(dr.Fields(i).name) + "</td>";
                }
                shtml += "</tr>";
                dr.moveNext;
            }
            shtml += "</table>";
            document.write(shtml);