An ASP connecting to read and write to an ACCESS database instance.
Here is an example of connecting to and reading/writing an Access database using ASP:
Firstly, make sure that the Microsoft Access Database Engine driver is installed on the server.
- Create an ASP page, for example, “connect.asp”.
- Add the following code to the ASP page:
<%
' 定义数据库文件路径
Const dbPath = "C:\path\to\your\database.mdb"
' 创建数据库连接对象
Set conn = Server.CreateObject("ADODB.Connection")
' 设置连接字符串
connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath
' 打开数据库连接
conn.Open connStr
' 查询数据
Set rs = conn.Execute("SELECT * FROM YourTableName")
' 输出查询结果
While Not rs.EOF
Response.Write rs("ColumnName") & "<br>"
rs.MoveNext
Wend
' 插入数据
conn.Execute "INSERT INTO YourTableName (ColumnName1, ColumnName2) VALUES ('Value1', 'Value2')"
' 关闭数据库连接
rs.Close
conn.Close
%>
- Change the value of the “dbPath” variable to the path of your Access database file.
- Change “YourTableName” to the name of the table where you want to query and insert data.
- Save the file and access the “connect.asp” page in the browser to display the retrieved data and insert new data into the database.
Please make sure that the path and table name of the database file are correct when connecting to an Access database using ASP. Additionally, ensure that the database file has read and write permissions for the IIS process user.