För databaskopplingar kan du kolla på https://www.connectionstrings.com
Sedan måste SQL-frågan ändras till:
SELECT TOP 10 * FROM aspbb_topics WHERE tforumid=1 ORDER BY tdatecreate DESC
6 svar · 406 visningar · startad av MadMange
Har denna kod som skall generera nyheter till ett forum, dock så använder jag mig av en Access databas och skulle nu behöva hjälp med att ändra från MySQL till Access, alltså db-kopplingen.
någon som har lust att hjälpa till? :r
2: <%
3:
4:
5:
6: '#################################################
7: '# Database options #
8: '#################################################
9:
10: const db_Server = "localhost"
11: const db_Password = "password"
12: const db_Username = "user"
13: const db_Database = "aspbb"
14:
15: 'Database connection
16: Dim objConn
17: Set objConn = Server.CreateObject("ADODB.Connection")
18: objConn.Open "Driver={MySQL ODBC 3.51 Driver};server="&db_Server&";uid="&db_Username&";pwd="&db_Password&";database="&db_Database&""
19:
20: '//Converts UNIX timestamps into the format the current webserver use.
21: Function uTimeStamp(byval dDate) '// Bring the date back from database and show in current session.LCID
22: on error resume next
23: uTimeStamp = DateAdd("s", dDate, "01/01/1970 00:00:00")
24: if err then
25: cTimeStamp = int(0)
26: end if
27: End Function
28:
29:
30: dim strSQL
31: strSQL = "SELECT * FROM aspbb_topics WHERE tforumid=1 ORDER BY tdatecreate DESC Limit 10"
32: set objNews = objConn.Execute(strSQL)
33:
34: Do Until objNews.EOF
35: Response.Write "<p><div style=""background-color:#f1f1f1; color:#ff7a00; font-size:12px""><img src=""mods/iconthread.gif"" style=""border:0"" /> <b>" & objNews("ttitle") & "</b> - " & uTimeStamp(objNews("tdatecreate")) & "</div><br/>" & vbNewLine
36: Response.Write objNews("tbody") & "<br/><br/><br/><br/>"
37: Response.write "<div style=""text-align:right""><a href=""http://forum.aspbb.org/topic.asp?TID=" & objNews("tid") & """>Comment</a></div>" & vbNewLine
38: Response.Write "<br/></p>" & vbNewLine
39: objNews.MoveNext
40: Loop
41:
42: objNews.Close : Set objNews = Nothing
43: objConn.Close : Set objConn = Nothing
44:
45: %>
För databaskopplingar kan du kolla på https://www.connectionstrings.com
Sedan måste SQL-frågan ändras till:
SELECT TOP 10 * FROM aspbb_topics WHERE tforumid=1 ORDER BY tdatecreate DESC
emission skrev:
För databaskopplingar kan du kolla på https://www.connectionstrings.com
Sedan måste SQL-frågan ändras till:
SELECT TOP 10 * FROM aspbb_topics WHERE tforumid=1 ORDER BY tdatecreate DESC
Ok nu ser det ut så här
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../db.mdb")
'//Converts UNIX timestamps into the format the current webserver use.
Function uTimeStamp(byval dDate) '// Bring the date back from database and show in current session.LCID
on error resume next
uTimeStamp = DateAdd("s", dDate, "01/01/1970 00:00:00")
if err then
cTimeStamp = int(0)
end if
End Function
dim strSQL
strSQL = "SELECT TOP 10 * FROM aspbb_topics WHERE tforumid=1 ORDER BY tdatecreate DESC"
set objNews = objConn.Execute(strSQL)
Do Until objNews.EOF
Response.Write "<p><div style=""background-color:#f1f1f1; color:#ff7a00; font-size:12px""><img src=""mods/iconthread.gif"" style=""border:0"" /> <b>" & objNews("ttitle") & "</b> - " & uTimeStamp(objNews("tdatecreate")) & "</div><br/>" & vbNewLine
Response.Write objNews("tbody") & "<br/><br/><br/><br/>"
Response.write "<div style=""text-align:right""><a href=""http://forum.aspbb.org/topic.asp?TID=" & objNews("tid") & """>Comment</a></div>" & vbNewLine
Response.Write "<br/></p>" & vbNewLine
objNews.MoveNext
Loop
objNews.Close : Set objNews = Nothing
objConn.Close : Set objConn = Nothing
%>
Men då får jag meddelandet :q
Microsoft VBScript runtime error '800a01a8'
Object required: 'objConn'
/news.asp, line 16
Ersätt samtliga förekomster av objConn med Conn (eller tvärtom).
Peter S skrev:
Ersätt samtliga förekomster av objConn med Conn (eller tvärtom).
OK!
Funkar detta tror du? (har lite prob med webhotellet)
<%
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../db.mdb")
'//Converts UNIX timestamps into the format the current webserver use.
Function uTimeStamp(byval dDate) '// Bring the date back from database and show in current session.LCID
on error resume next
uTimeStamp = DateAdd("s", dDate, "01/01/1970 00:00:00")
if err then
cTimeStamp = int(0)
end if
End Function
dim strSQL
strSQL = "SELECT TOP 10 * FROM aspbb_topics WHERE tforumid=1 ORDER BY tdatecreate DESC"
set objNews = objConn.Execute(strSQL)
Do Until objNews.EOF
Response.Write "<p><div style=""background-color:#f1f1f1; color:#ff7a00; font-size:12px""><img src=""mods/iconthread.gif"" style=""border:0"" /> <b>" & objNews("ttitle") & "</b> - " & uTimeStamp(objNews("tdatecreate")) & "</div><br/>" & vbNewLine
Response.Write objNews("tbody") & "<br/><br/><br/><br/>"
Response.write "<div style=""text-align:right""><a href=""http://forum.aspbb.org/topic.asp?TID=" & objNews("tid") & """>Comment</a></div>" & vbNewLine
Response.Write "<br/></p>" & vbNewLine
objNews.MoveNext
Loop
objNews.Close : Set objNews = Nothing
objConn.Close : Set objConn = Nothing
%>
Tycker det ser rätt ut.