搜尋此網誌

2011年12月6日 星期二

asp讀取資料庫範例碼(較正規)


dim DSN, Conn, Rs
DSN = "Driver={SQL Server};Server=dbname;UID=id;PWD=password;"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open DSN
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open "Select * From [db].dbo.[table] Where 1 = 1", Conn, 3, 1
If Rs.RecordCount > 0 And Not Rs.EOF Then
 response.write(Rs(0))
End If
Rs.Close: Set Rs = Nothing
Conn.Close: Set Conn = Nothing