Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Cant read data from table? I dont know why?

Hi friends,
I am developing a website which includes daily news page. I have added a "read more" link after the news summary. It opens a new page with an address like that :
"http://domainname.com/news/news_detail.asp?newsID=12"
12 may vary depending on the newsID on the data table.

After that I am adding the codes of news_detail.asp file: Here you are:
<% @ Language=VBScript %>
<% Option Explicit %>
<%

Dim ... ' Assigning required variables...

Set adoCon = Server.CreateObject("Adodb.Connection")
adoCon.open = "Provider=Microsoft.Jet.Oledb.4.0;Data Source="& Server.MapPath("../../db_.mdb") &";"
Set rs = Server.CreateObject("Adodb.Recordset")
rs.Open "SELECT * FROM tblNews WHERE newsID = "& CInt(strNewsID) &"", adoCon, 1, 3

strnews = Trim(Request.QueryString("newsID"))

'// reading news info.
intcontentID = rs("newsID")
strContent = rs("news")
dtmnewsDate = kd("newsdate")
strnewsHead = kd("newshead")
strnewsImg = kd("image")

kd.Close
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><%=strnewsHead%></title>
</head>
<body>
<table width="556" height="513" border="2" align="left" cellpadding="2" cellspacing="0" bordercolor="#FFFFCC" class="tabloGolgeli">
<tr><td height="50"><div align="center">nbsp;<%=formatMyDate(dtmnewsDate,0)%> ]<%=strnewsHead%></div></td>
</tr>
<tr>
<td width="556" height="463" align="left" valign="top"><img src="<%=Trim(strnewsImage)%>" alt="<%=strnewsHead%>" border="1" vspace="2" hspace="2" align="left" style="max-height:200px" /> <%=strContent%> </td>
</tr>
</table>
</body>
</html>

Page opens very well. But there is no text. I see that this code cannot read data from table into page. I do not know how I can fix it. So, that is why I am here: I NEED UR HELP.

Email Removed By Mod
[2178 byte] By [ozkanozlu] at [2007-11-11 11:59:07]
# 1 Re: Cant read data from table? I dont know why?
I have edited your post and removed your email address.

You should never post your email address in an open post on an open forum. Mail spam bots can pick that up and before you know it, your mailbox is full of junk mail. If you wish to share your email address with other forum members, please do so via our PM system.

In addition, we prefer all answers to questions be publically posted rather than sent via EMail or PM. That way, everyone with a similar problem can benefit.

Thanks. :)
Hack at 2007-11-11 23:34:01 >
# 2 Re: Cant read data from table? I dont know why?
Well what do you expect when you use a variable before declaring it and also using a completely different variable afterwards?

Your code shows that you declared strnews after using it in your SQL statement.
It should be the other way round.

Dim strnews ' Assigning required variables.. and other variables.

' Now set strnews to receive the querystring

strnews = Trim(Request.QueryString("newsID"))

Set adoCon = Server.CreateObject("Adodb.Connection")
adoCon.open = "Provider=Microsoft.Jet.Oledb.4.0;Data Source="& Server.MapPath("../../db_.mdb") &";"
Set rs = Server.CreateObject("Adodb.Recordset")

' Also making sure that newsID is a column in the table

rs.Open "SELECT * FROM tblNews WHERE newsID = "& CInt(strnews) &"", adoCon, 1, 3

'// reading news info.
intcontentID = rs("newsID")
strContent = rs("news")
dtmnewsDate = kd("newsdate")
strnewsHead = kd("newshead")
strnewsImg = kd("image")

kd.Close
%>
Emefa at 2007-11-11 23:35:07 >
# 3 Re: Cant read data from table? I dont know why?
dtmnewsDate = kd("newsdate")

....where did the object "kd" come from??
bschaettle at 2007-11-11 23:36:05 >