javascript访问sql2000

 

<script language="javascript">
function DB_looked()
{
    var ConnDB = new ActiveXObject("adodb.connection");
var rs = new ActiveXObject("ADODB.Recordset");
var sql = "select * from dbo.Company_user where C_count=0 ";
ConnDB.ConnectionString="DSN=BHN_exhibit;uid=;pwd=";
ConnDB.open
rs.open(sql,ConnDB,1,1);
    if (rs.RecordCount>0){

   if (parseInt(rs("C_count"))==0){
  
   //字符串连接
  
   document.all('txt').value = rs("C_name");
  
   var sql=null;
  
   rs.close
  
   ConnDB.close
  
   return;
  
   } else {
  
   var sql=null;
  
   alert("没有此代号!");
  
   txt.select();
  
   txt.focus();
  
   rs.close
  
   ConnDB.close
  
   }
  
   }
  
  

}
</script>
</head>

<body>
<input type=text id=txt name=txt onblur="DB_looked()">


正确的访问:
<script language="javascript" runat="server"> //注意:runat="server"
var conn=new ActiveXObject("Adodb.Connection");
var rs=new ActiveXObject("Adodb.Recordset");
var sqlstr;
conn.ConnectionString="Driver={SQL Server};server=wjl;uid=sa;pwd=;database=BHN_exhibit;";
conn.Open();
sqlstr="select * from dbo.Company_user";
rs.Open(sqlstr,conn,3);
while(!rs.EOF)
{
Response.Write(rs("C_name"));
Response.Write("<br>");
rs.MoveNext;
}
</script>


你可能感兴趣的:(javascript访问sql2000)