...

View Full Version : "SELECT" statement & conditions..



enrmpaga
04-27-2006, 11:28 AM
I'm using SQL/ASP, I'm trying to pull a record from one mdb table and copy it to another mdb table, but i'm having some problems.. here is my code:

Line 1>Sql_sel = "SELECT Top 1 CUSTID FROM cust ORDER by CUSTID DESC"
Line 2>CUSTID = Sql_sel
Line 3>response.write(CUSTID)

Line 1, CUSTID being the ID field, cust being the table which holds the records.
Line 3, is a test to see if it pulls the right data, unfortunately it doesn't infact where i was expecting to see the lastest CUSTID displayed it infact just displays Line 1 as i have written it. This mkaes me beleive that i have made a simple syntax error.. can anyone spot any faults?

Roelf
04-27-2006, 02:14 PM
you might want to check here: http://www.w3schools.com/ado/ado_examples.asp to see what you need to extract and manipulate data in a database from an asp page. There are some simple examples. Use and modify them to achieve your desired results

Archangel
04-28-2006, 04:46 PM
You're missing your connection to the Database and the Recordset to pull the data back. Almost looks like you're trying to do it in PHP fashion...completely different...Here is something like I use for a connection to the DB...

'Set the Connection Object --------------------------------------------------------------
'Define connection object
Dim conn
SET conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString = "Provider=SQLOLEDB.1;Password=password;Persist Security Info=True;User ID=userid;Initial Catalog=table;Data Source=database"
conn.CommandTimeout = 30
conn.ConnectionTimeout = 30
conn.open
'----------------------------------------------------------------------------------------


Once that is setup then you would do...

Dim Sql_sel, RS
'Set up recordset
Set RS = Server.CreatObject("ADODB.Recordset")
Sql_sel = "SELECT Top 1 CUSTID FROM cust ORDER by CUSTID DESC"

RS.Open Sql_sel, conn

Response.Write RS.Fields("CUSTID")



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum