【问题标题】:Make a connection to Sql Server using Classic ASP使用经典 ASP 连接到 Sql Server
【发布时间】:2018-03-07 00:08:12
【问题描述】:

我创建了一个带有 action 属性的表单。我可以从 web 表单中获取值并使用我的 action_page 显示它们(response.write...用于澄清我的值正在被读取)。我还在 MS Studio Management 上创建了一个数据库和一个表。我坚持的步骤是连接 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>")  
  %>

【问题讨论】:

  • 这似乎是带有 VBScript 的 Classic ASP,与 VB.Net 无关。见MSDN: How To Create a Database Connection from an ASP Page in IIS
  • 你为什么要在这种过时的氛围中学习编码?经典的 ASP 早已死去。有大量网站仍在运行,但既然您似乎对开发世界很陌生,为什么不使用更现代的语言?
  • “如何使用现代方法编写上述内容”远远超出了 Stack Overflow 上的问题范围。放下你所做的,找到一个 C# 中的 ASP.NET 教程(最好使用现代约定,如 MVC,也许是 ASP.NET Core 等)。
  • 以上是cmets,不是答案。将 cmets 视为一种讨论,一种用于进一步理解问题或问题意图的工具。我也同意你的观点,这些都不是很好的答案。 cmets 都建议如果 OP 试图找到一个学习项目,那么从过时的语言和框架开始是没有帮助的。实际上,这方面的工作机会或未来增长并不多。为过时的语言/框架寻找资源和帮助也可能具有挑战性。我的 2 美分。

标签: sql-server vbscript asp-classic


【解决方案1】:

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

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

Provider=SQLNCLI11;Server=myServerAddress;Database=myDataBase;Uid=myUsername; 密码=我的密码;

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

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

现在您可以向/从数据库发送和检索数据。有任何问题,欢迎提问!

【讨论】:

  • 非常感谢。非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多