使用 Classic ASP 与 Sql Server 建立连接



我创建了一个带有操作属性的表单。我能够从网络表单中获取值并显示它们(响应.write...用于澄清我的值正在被读取(使用我的action_page。我还创建了一个关于MS Studio管理的数据库和表格。我坚持的步骤是连接 Web 表单值和数据库所需的代码。谢谢。注意:这是操作页面,我没有包含表单。注意:我使用的是记事本++而不是Visual Studio。

<%@ Language="VBscript" %>
<%
'declare the variables that will receive the values 
 Dim name 
 Dim idnum 
 Dim product
 Dim entrydate
 Dim area
 Dim qunaity
 'receive the values sent from the form and assign them to variables
  quantity=Request.Form("quantity")
  area=Request.Form("area")
  entrydate=Request.Form("date")
  stack over
 'let's now print out the received values in the browser
  Response.Write("Name: " & name & "<br>")
  Response.Write("Quantity: " & quantity & "<br>")
  Response.Write("Area: " & area & "<br>")
  Response.Write("Date: " & entrydate & "<br>")  
  %>

同样,不要听那些说"重新开始"的人,作为Web开发的初学者学习经典asp,因为它很容易学习,并且会让你掌握Web开发的基础知识。

查看 ConnectionStrings.com 以帮助查找适合你的连接字符串。如果您安装了正确的驱动程序(在这种情况下,您应该这样做(,您可能会摆脱这样的事情:

提供程序 = SQLNCLI11;Server=myServerAddress;Database=myDataBase;uid=我的用户名;Pwd=我的密码;

所以你的代码可能看起来像这样:

<%@ Language="VBscript" %>
<%
'declare the variables that will receive the values 
 Dim name 
 Dim idnum 
 Dim product
 Dim entrydate
 Dim area
 Dim qunaity
 'receive the values sent from the form and assign them to variables
  quantity=Request.Form("quantity")
  area=Request.Form("area")
  entrydate=Request.Form("date")
  stack over
 'let's now print out the received values in the browser
  Response.Write("Name: " & name & "<br>")
  Response.Write("Quantity: " & quantity & "<br>")
  Response.Write("Area: " & area & "<br>")
  Response.Write("Date: " & entrydate & "<br>")  
  '-- now, connect to the database
  dim conn : set conn = Server.CreateObject("ADODB.Connection")
  dim connString : connString = "Provider=SQLNCLI11;Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;"
  conn.Open connString
  %>

现在,您可以向数据库发送数据/从数据库检索数据。任何问题,请随时提问!

最新更新