使用Classic ASP建立与Sql Server的连接

时间:2018-03-06 14:42:46

标签: sql-server vbscript asp-classic

我创建了一个带有action属性的表单。我可以使用我的action_page从Web表单中获取值并显示它们(response.write ...用于澄清我的值被读取)。我还在MS Studio Management上创建了一个数据库和一个表。我坚持的步骤是连接Web表单值和数据库所需的代码。谢谢。 注意:这是操作页面,我没有包含表单。 注意:我使用的是notepad ++而不是visual studio。

EVENTDATA()

1 个答案:

答案 0 :(得分:0)

再一次,不要听那些说'#34;重新开始'的人,将经典的asp作为网络开发的初学者学习,因为它易于学习并且会为你提供基础知识web dev。

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

提供商= SQLNCLI11;服务器= myServerAddress;数据库= MYDATABASE; UID =名为myUsername; PWD = MYPASSWORD;

因此您的代码可能如下所示:

<%@ 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
  %>

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