永发信息网

求asp 连接 mssql 并新增一条记录 的代码

答案:2  悬赏:80  手机版
解决时间 2021-01-31 05:43
  • 提问者网友:棒棒糖
  • 2021-01-30 17:44
我在网上居然搜不到 汗。。
最佳答案
  • 五星知识达人网友:蕴藏春秋
  • 2021-01-30 19:11
<%
'declare the variables
Dim 
Connection
Dim Recordset
Dim SQL

'declare the SQL statement that will query the database
sql="INSERT INTO customers (customerID,companyname,"
sql=sql & "contactname,address,city,postalcode,country)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("custid") & "',"
sql=sql & "'" & Request.Form("compname") & "',"
sql=sql & "'" & Request.Form("contname") & "',"
sql=sql & "'" & Request.Form("address") & "',"
sql=sql & "'" & Request.Form("city") & "',"
sql=sql & "'" & Request.Form("postcode") & "',"
sql=sql & "'" & Request.Form("country") & "')"

'create an instance of the ADO connection and recordset objects
Set Connection = Server.CreateObject("ADODB.Connection")

'open the connection to the database
Connection.Open 
"DSN=dsn_name;UID=user_name;PWD=password;Database=database_name"

on error resume next
conn.Execute sql,recaffected
if err<>0 then
 Response.Write("No update permissions!")
else
 Response.Write("" & recaffected & " record added")
end if

Connection.Close
Set Connection=nothing
%>
全部回答
  • 1楼网友:詩光轨車
  • 2021-01-30 19:21
你查下,看你表中的数据类型与你插入的数据类型是否一致。已经提示了:“'`' 附近有语法错误”。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯