Connect to Access DatabaseUpload ImagesLink Kevin Robertson 2 years ago
I am attempting to connect to my database using ASP.Net in Expression Web. I am using the following code:
dim conn dim rs conn = server.createobject("ADODB.Connection") conn.open ("StoreDSN") rs = server.createobject("ADODB.Recordset") rs.activeconnection = conn rs.open ("SELECT ProductID, ProductName FROM ProductT") while not rs.eof response.write (rs("ProductName")) rs.movenext end while
When I navigate to the page I get the following result: System.__ComObject
Repeating for every record in the database. Any ideas?
DatabasePath = "/full/path/to/your/database/whatever.mdb"
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider="Microsoft.Jet.OLEDB.4.0;"
Conn.Open Server.MapPath(DatabasePath)
You shouldn't need the rs.ActiveConnection line.
And remember you don't need parentheses around statements that aren't functions and don't return a value. For example:
response.write rs("ProductName")
You don't need parens around that because you aren't returning a value from it.
Kevin Robertson 2 years ago
Thank Richard, finally got it working. Initially ran into the same problem until I made the followong change:
response.write (rs("ProductName").Value)
Set is apparently no longer supported, so had to leave it off. Tried without the parentheses and got on error message. Compiler Error Message: BC30800: Method arguments must be enclosed in parentheses.
Thank you once again and keep up the great work you are doing.
Well that's news to me. I have done very little with ASP.NET. A few pages here and there to do specific things not supported in Classic ASP (like file uploads).
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.