使用经典ASP建立与Sql Server的连接 [英] Make a connection to Sql Server using Classic ASP

查看:139
本文介绍了使用经典ASP建立与Sql Server的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a form with an action attribute. I am able to take the values from the web form and display them (response.write...used for clarification that my values are being read) using my action_page. I have also created a database and a table on MS Studio Management. The step i'm stuck on is the code that is required in order to connect the web form values and the database. Thanks. Note: This is the action page, I did not include the form. Note: I am using notepad ++ and NOT 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,因为它很容易学习,并且会得到您是网络开发人员的基础.

Again, don't listen to those who say "start over", learning classic asp as a beginner to web dev, as it's easy to learn and will get you the basics of web dev.

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

Check out ConnectionStrings.com to help finding the right connection string for you. If you have the right drivers installed (which, in this case, you should), you can probably get away with something like this:

Provider = SQLNCLI11; Server = myServerAddress; Database = myDataBase; Uid = myUsername; Pwd = myPassword;

Provider=SQLNCLI11;Server=myServerAddress;Database=myDataBase;Uid=myUsername; Pwd=myPassword;

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

so your code may look something like this:

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

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

now you can send and retrieve data to/from the database. Any questions, feel free to ask!

这篇关于使用经典ASP建立与Sql Server的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆