A lot of online friends feel very confused when solving some problems, and many people think that the JavaScript connection database is not understood, and even if JavaScript can only be executed by the client, can not connect to the database. And I look for it, the 9CBS introduced is too traditional, the beginners can't understand, and I have no search for other forums. In this case, I decided to look at MSDN, and summarize the method of connecting the JavaScript connection database by reading the example of the connection database of VC .
// ^ _ ^
//
// (c) in 2002-2003 by Alex (Chinese: Jiang Jianhua)
//http://www.finder.net.cn
// c email: jiangjh@finder.net.cn
// f email: jjh_115@eyou.com
script>
Function Replace (V)
{
// Fault tolele, please make a judgment of the reader.
/ / Define SQL statements
Var SQL = "SELECT * from Dictionary where mainid = '" v "'"
// New database connection object and data set access object
VAR connd = new activxObject ("adodb.connection");
Var = New ActiveXObject ("AdoDb.Recordset");
// Here you fill in the DSN you want to connect
Conndb.connectionstring = "DSN = ***; uid = ***; pwd = ***";
CONNDB.OPEN
Rs.Open (SQL, Conndb, 1, 1);
IF (Rs.Recordcount> 0) {
IF (v == PARSEINT (RS ("mainid"))) {
// String connection
Document.all ('txt'). Value = V RS ("MainValue");
Var SQL = NULL;
Rs.close
Conndb.close
Return;
} else {
Var SQL = NULL;
Alert ("No this code!");
TXT.SELECT ();
TXT.FOCUS ();
Rs.close
Conndb.close
}
}
script>