|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello guys...I'm migrating to SQL 2000 and ASP having C/C++ background....I need to develop a project for my work....I need to develop a simple ASP module which will connect to a simple SQL 2000 database.....let's say that this database has only three columns...lastN, middleN, and firstN (really basic database)....what I'm trying to accomplish is the following....1) be able to connect to the database from an ASP page 2) ASP page should allow to manipulate database records (really simple functions such as add, modify, delete records)...like i said I'm kinda new at this....I tried to make the connection but it didnt work...this is what i did....I made my connection in the global.asa as follows
---global.asa---- <SCRIPT LANGUAGE="VBScript" RUNAT="Server"> Sub Application_OnStart() Dim strConn strConn = "Provider=SQLOLEDB.1; Data Source=servername; Initial Catalog=databasename; User Id=username; Password=password" Application("strConn") = strConn End Sub </Script> ---test.asp--this page is not trying to do any functions other than making the connection to the database and displaying records 1 <% Option Explicit %> 2 <html> 3 <head> 4 <title>test asp page</title> 5 </head> 6 <body> 8 <ol> 9 <% 10 Dim objConn 11 Set objConn = Server.CreateObject("ADODB.Recordset") 12 objConn.Open "table's name", Application("strConn") 13 14 Do While Not objConn.EOF 15 Response.Write "<li><b>" & objConn("lastN") & "</b>" 16 Response.Write "<p>" & objConn("firstN") & "</p></li>" 17 objConn.MoveNext 18 Loop 19 If objConn.BOF Then 20 Response.Write "<p>No more records in the database!</p>" & vbNewLine 21 End If 22 23 objConn.Close 24 %></ol> 25 </body> 26 </html> I know that you guys will look at this and it'll be a simple problem...once again...im only a newbie at this..so any help would be greatly appreciated....maybe someone can point me in the right direction.....Thanks! P.S. what I'm trying to accomplish here....is to connect a simple database to a page and show the records of that database (only 3 names stored in the database) |
|
#2
|
|||
|
|||
|
coraxal,
Hi! You need to query the database in order to retrieve any data from it. That means you needs to write SQL queries. There are many ways to do this. Try adding: strSQL = "SELECT * FROM table_name" Set objRS = objConn.Execute (strSQL) between lines 12 and 14 and then changing objConn to objRS in lines 14, 17, and 19. You will also want to close the objRS object before the script ends. You might want to check out a tutorial about ADO and/or SQL. Hope this helps. |
|
#3
|
|||
|
|||
|
hi coraxal,
to add to markerdave: Code:
Dim oConn, oRs
Set oConn = Server.CreateObject("ADODB.Connection")
oCnn.Open Application("strConn")
Set oRS = oConn.Execute ("SELECT * FROm tablename")
If oRS.EOF Then
Response.WRite "no records found<BR>"
Else
Do While Not oRs.EOF
Response.Write oRs.Fields("field1") & "<BR>"
Loop
End If
oRs.Close
Set oRs = Nothing
'important that you close the connection!
oCnn.Close
Set oCnn = Nothing
-Rogier
__________________
- Rogier Doekes |
|
#4
|
|||
|
|||
|
Thanks
Thanks very much guys.....I'll try that...
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > newbie here |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|