我想从SQL Server数据库中获取数据 [英] I wanted to get data from SQL server databse

查看:74
本文介绍了我想从SQL Server数据库中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在html中使用javascript从sql server数据库获取数据





<!DOCTYPE HTML> 
< html>
< head>
< meta http-equiv =content-typecontent =text / html; charset = utf-8/>
< title>数据库连接< / title>
< script type =text / javascript>

var connection = new ActiveXObject(ADODB.Connection);

var connectionstring =Data Source = GD-04\SQLEXPRESS; Initial Catalog = Employee; User ID = sa; Password = grassdew; Provider = SQLOLEDB;

connection.open(connectionstring);
var rs = new ActiveXObject(ADODB.Recordset);
var strQuery =SELECT * FROM Customer_Orders;
rs.Open(strQuery,connection);
rs.MoveFirst();
while(!rs.EOF){
document.write(rs.fields(0)+& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& NBSP;&安培; NBSP;&安培; NBSP;);
document.write(rs.fields(1)+& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;) ;
document.write(rs.fields(2)+& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;) ;
document.write(rs.fields(3)+& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;) ;
document.write(rs.fields(4)+& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;) ;
document.write(rs.fields(5)+< br />);
rs.movenext();
}

rs.close();
connection.close();


< / script>
< / head>
< body>
< div id =main>< / div>
< / body>
< / html>

解决方案

1)ActiveXObject(ADODB.Recordset)通常不可用(当然在所有我的系统) - 并且'斑点'可用性使它无用。



2)这将教你如何: PHP 5教程 [ ^ ] PHP是一种非常广泛使用的服务器端语言。



在他们谈论访问MySQL的教程中 - 有插件驱动程序可用来自Microsoft提供对SQL的php访问。 从官方Microsoft下载中心下载适用于SQL Server的PHP的Microsoft驱动程序 [ ^ ]



你会注意到php与javascript并没有太大的不同 - 至少在于它遵循C语法,如果你已经学过'C'那么你就知道了很多它的库已经。





这是获取数据的好方法,非常感谢你。

i tried to get data from sql server database using javascript in html


<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Database Connect</title>
    <script type="text/javascript">

        var connection = new ActiveXObject("ADODB.Connection");

        var connectionstring = "Data Source=GD-04\SQLEXPRESS;Initial Catalog=Employee;User ID=sa;Password=grassdew;Provider=SQLOLEDB";

        connection.open(connectionstring);
        var rs = new ActiveXObject("ADODB.Recordset");
        var strQuery = "SELECT * FROM Customer_Orders";
        rs.Open(strQuery, connection);
        rs.MoveFirst();
        while (!rs.EOF) {
            document.write(rs.fields(0) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
            document.write(rs.fields(1) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
            document.write(rs.fields(2) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
            document.write(rs.fields(3) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
            document.write(rs.fields(4) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
            document.write(rs.fields(5) + "<br/>");
            rs.movenext();
        }

        rs.close();
        connection.close();


    </script>
</head>
<body>
    <div id="main"></div>
</body>
</html>

解决方案

1) ActiveXObject("ADODB.Recordset") is generally unavailable (certainly on all of my systems) - and 'spotty' availability makes it useless.

2) This will teach you how: PHP 5 Tutorial[^] PHP is a very widely available server-side language.

inside the tutorial they talk about accessing MySQL - there are plug-in drivers available from Microsoft for giving php access to SQL. Download Microsoft Drivers for PHP for SQL Server from Official Microsoft Download Center[^]

You'll notice that php isn't a whole lot different than javascript - at least in that it's follows C syntax, and if you've ever learned 'C' then you know a lot of it's library, already.



It is great memthod to get data, thank you a lot.


这篇关于我想从SQL Server数据库中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆