Can I do INSERT and UPDATE classic ASP style?

Ø

Ø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
 
C

Cowboy \(Gregory A. Beamer\)

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top