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

问题描述 投票:-2回答:1

我创建了一个带有action属性的表单。我可以使用我的action_page从Web表单中获取值并显示它们(response.write ...用于澄清我的值被读取)。我还在MS Studio Management上创建了一个数据库和一个表。我坚持的步骤是连接Web表单值和数据库所需的代码。谢谢。注意:这是操作页面,我没有包含表单。注意:我使用的是notepad ++而不是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>")  
  %>
sql-server vbscript asp-classic
1个回答
0
投票

再一次,不要听那些说“重新开始”的人,学习经典的asp作为web开发者的初学者,因为它易于学习,并将为您提供Web开发的基础知识。

查看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
  %>

现在您可以向/从数据库发送和检索数据。有任何问题请随时询问我(们!

© www.soinside.com 2019 - 2024. All rights reserved.