ASP Operations Database Access

Source: Internet
Author: User

The initial leadership assignment is to use VB to connect the database, and later because I do not understand VB, and use JS

Vb,js is a client language and can only be run locally. Can no longer run on server

The reason is that the local connection database address can use a relative or absolute path, and the location of the database is not able to get the server file address locally!

I look at the major forums online and paste, find the Server object method MapPath can get the file path

The error message server object is not defined by the Small series test server to get the path. After changing to ASP code, run normally!

Get database connection

<%
Set conn = Server.CreateObject ("ADODB. Connection ")//Get service Driver
Conn. Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("#abc. mdb")//Set connection database to access driver, specify database file
Set Rs=server.createobject ("Adodb.recordset")//Create service return object

%>

Add data

<%
User=request.form ("Po.loginname")
Pwd=request.form ("password")

Sql= "SELECT * from [user] where user= '" +user+ "' and pwd = '" +pwd+ "'"
Rs.Open sql,conn,1,1

%>

Update data

<%

User=request.form ("User")
Pwd=request.form ("pwd")

Sql= "SELECT * from [user] where user= '" +user+ ""
Rs.Open sql,conn,1,3
If Rs.recordcount>0 Then
Response.Write ("<script>alert (' user already registered, please login!") '); javascript:window.location.href= ' Login.asp ' </script> ")
Response. End ()
End If
Rs.addnew
RS ("user") =user
RS ("pwd") =pwd

Rs.update
Response.Write ("<script>alert" (' Registered success!); javascript:window.location.href= ' login.asp ' </script> ')
Response. End ()
Rs.close
Conn.close
%>

ASP Operations Database Access

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.