如何通过连接字符串通过asp插入值tosqlserver 2000

时间:2010-08-12 06:10:31

标签: sql asp-classic

.....................

1 个答案:

答案 0 :(得分:1)

希望以下代码可以帮助您

了解更多详情:Active Server Pages Tutorial

   <%

    Dim conn

    Set conn = Server.CreateObject("ADODB.Connection")

    conn.Open "Provider=SQLOLEDB; Data Source = (local); Initial Catalog = Northwind; User Id = sa; Password="

    If conn.errors.count = 0 Then

    set cm = Server.CreateObject("ADODB.Command")
        cm.ActiveConnection = conn 
    'Define SQL query
        cm.CommandText ="INSERT INTO Guestbook (TB1,TB2,TB3,TB4,MB1)
             VALUES (?,?,?,?,?)"
        'Define query parameter configuration information for guestbook fields
        set objparam=cm.createparameter(, 200, , 255, strTB1)
        cm.parameters.append objparam
         set objparam=cm.createparameter(, 200, , 255, strTB2)
         cm.parameters.append objparam
         set objparam=cm.createparameter(, 200, , 255, strTB3)
          cm.parameters.append objparam
        set objparam=cm.createparameter(, 200, , 255, strTB4)
         cm.parameters.append objparam
         set objparam=cm.createparameter(, 201, , iLenMB1, strMB1)
        cm.parameters.append objparam
         cm.execute
        response.write("Thank you!")

    End If

    conn.Close
   Set conn = Nothing
    %>