Can I do INSERT and UPDATE classic ASP style?

Discussion in 'ASP .Net' started by Øyvind Henriksen, Feb 26, 2005.

  1. Is there a way to do this in ASP.Net (without writing strings
    with UPDATE/INSERT SQL statements) ?

    --

    SQL = "SELECT * FROM Login_IP WHERE IP='" & IP & "' AND Username='" &
    lcase(usr) & "';"
    Set RS = Server.CreateObject ("ADODB.RecordSet")
    RS.ActiveConnection = Hovedbase
    RS.CursorType = 1
    RS.LockType = 2
    RS.source = SQL
    RS.Open
    If RS.EOF Then
    RS.AddNew()
    RS("IP") = IP
    RS("Username") = lcase(usr)
    End IF
    RS("Dato") = Date()
    RS.Update()
    RS.Close
    Set RS = Nothing

    --

    TIA,

    Øyvind Henriksen
    Systems engineer

    Tlf: +47 982 51 014
    Fax: +47 45 50 97 05
    ___________________________________
    InCreo Interactive Creations AS
    Po box 1241, Pirsenteret, 7462 Trondheim
    Service nr: +47 815 51 888 Fax: +47 455 09 679
    Org.nr.: NO 982 057 892 www.increo.no
    Øyvind Henriksen, Feb 26, 2005
    #1
    1. Advertising

  2. Look at the documentation for the DataAdapter. The basic method is:

    1. Set up connection
    2. Set up command, which is easier than ASP

    Dim cmd as New SqlCommand("SELECT * FROM Login_IP WHERE IP=@IP AND
    UserName=@UserName", conn)

    3. Add the parameter objects for @IP and @UserName
    4. Run the command
    5. Update the items with the lowercase version

    Dim s As String = MyDataSet.Tables[0].Rows[0]["UserName"].ToLower()
    MyDataSet.Tables[0].Rows[0]["UserName"] = s

    6. Run Update on the Adapter

    MyDataAdapter.Update()

    Check the documentation and it will become clear. Dino Esposito has some of
    the best articles on ADO.NET. You can find them on the MSDN website
    (http://msdn.microsoft.com).

    NOTE: With OLEDB, you use ? rather than named parameters in the SQL
    statement.

    Dim cmd as New SqlCommand("SELECT * FROM Login_IP WHERE IP=? AND
    UserName=?", conn)

    --
    Gregory A. Beamer
    MVP; MCP: +I, SD, SE, DBA

    *************************************************
    Think outside the box!
    *************************************************
    "Øyvind Henriksen" <> wrote in message
    news:#...
    > Is there a way to do this in ASP.Net (without writing strings
    > with UPDATE/INSERT SQL statements) ?
    >
    > --
    >
    > SQL = "SELECT * FROM Login_IP WHERE IP='" & IP & "' AND Username='" &
    > lcase(usr) & "';"
    > Set RS = Server.CreateObject ("ADODB.RecordSet")
    > RS.ActiveConnection = Hovedbase
    > RS.CursorType = 1
    > RS.LockType = 2
    > RS.source = SQL
    > RS.Open
    > If RS.EOF Then
    > RS.AddNew()
    > RS("IP") = IP
    > RS("Username") = lcase(usr)
    > End IF
    > RS("Dato") = Date()
    > RS.Update()
    > RS.Close
    > Set RS = Nothing
    >
    > --
    >
    > TIA,
    >
    > Øyvind Henriksen
    > Systems engineer
    >
    > Tlf: +47 982 51 014
    > Fax: +47 45 50 97 05
    > ___________________________________
    > InCreo Interactive Creations AS
    > Po box 1241, Pirsenteret, 7462 Trondheim
    > Service nr: +47 815 51 888 Fax: +47 455 09 679
    > Org.nr.: NO 982 057 892 www.increo.no
    >
    >
    Cowboy \(Gregory A. Beamer\), Feb 26, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    7,770
    elizas
    Apr 27, 2010
  2. Chris S.

    Classic and New Style Classes?

    Chris S., Jun 24, 2004, in forum: Python
    Replies:
    5
    Views:
    357
    Chris S.
    Jun 24, 2004
  3. ankit
    Replies:
    1
    Views:
    340
    Alex Martelli
    Dec 22, 2005
  4. Ken Varn
    Replies:
    0
    Views:
    450
    Ken Varn
    Apr 26, 2004
  5. OnRails Ruby
    Replies:
    2
    Views:
    144
    bbiker
    Oct 20, 2007
Loading...

Share This Page