Can I do INSERT and UPDATE classic ASP style?

  • Thread starter Thread starter Øyvind Henriksen
  • Start date Start date
Ø

Øyvind Henriksen

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
 
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!
*************************************************
 
Back
Top