Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

data from database not appears...

i'm try running this code..

<html><head><title>Carian Harta </title></head>
<BODY><body background="blegtext.gif">

<p align="center" background="blue"><b><font size="5" font color=blue>SENARAI CARIAN</font></b><p>

<hr>


<%

pilihan      =Request.Form("pilihan")
nilai      =Request.Form("nilai")

'########## DSN-less connections ############################################################################################
Dim DBName, objConn, rs, strSQL      '//Variables we need
DBName = server.mappath("spick98.mdb")'//Database file !CHANGE IF NEEDED!

'//Create ADO connection
Set objConn = Server.CreateObject("ADODB.Connection")

'//Open our student database with this string
objConn.ConnectionString = "DBQ=" & DBName & ";Driver={Microsoft Access Driver (*.mdb)};"

'//Access our database
objConn.Open DAFTARHARTASH01

'//Create a recordset
Set rs = Server.CreateObject("ADODB.Recordset")
'######################################################################################################


If pilihan="No Harta1" Then
       strSQL="SELECT* FROM DAFTARHARTASH01 WHERE no_harta1=' " & nilai & " ' "
       set rs=objConn.execute(strSQL)
      bil=0

      response.Write("<hr><table border=" & 2)
      response.Write("<tr><td>Bil.</td><td>No Harta1</td><td>Jenama</td><td>No Siri</td></tr>")


Do While NOT rs.EOF
      bil=bil + 1
      response.Write("<tr><td><b>" & bil & "</b></td>")
      response.Write("<td><b>" & rs("no_harta1") & "</b></td>")
      response.Write("<td><b>" & rs("jenama")  & "</b></td>")      
      response.Write("<td><b>" & rs("no_siri") & "</b></td></tr>")
      
 rs.MoveNext
 Loop
      response.Write("</table border>")

If bil = 0 THEN
      response.Write("<hr><h2>Tiada Rekod</h2>")
       End If

Else
strSQL="SELECT no_harta1,jenama,no_siri FROM DAFTARHARTASH01 WHERE no_siri =' " & nilai & " ' "
       set rs1=objConn.execute(strSQL)
      bilangan=0
      response.Write("<hr><table border=" & 2 )
      response.Write("<tr><td>Bil.</td><td>No Harta1</td><td>Jenama</td><td>No siri</td></tr>")

 Do While NOT rs1.EOF
      bilangan=bilangan + 1
      response.Write("<tr><td><b>" & bilangan & "</b></td>")
      response.Write("<td><b>" & rs1("no_harta1") & "</b></td>")
      response.Write("<td><b>" & rs1("jenama")  & "</b></td>")      
      response.Write("<td><b>" & rs1("no_siri") & "</b></td></tr>")
      
rs1.MoveNext
Loop
      response.Write("</table border>")
 If bilangan = 0 THEN
      response.Write("<hr><h2>Tiada Rekod</h2>")
       End If
 End If


%>
</body></html>


there are no errors, the output display but data i'm searching from data base not appears...why????

0
eez81
Asked:
eez81
  • 2
  • 2
1 Solution
 
appariCommented:
i think no data is returned, check the sql and run it in mdb and see whether the sql is returning any data or not.

and in the sql you are building
>>strSQL="SELECT no_harta1,jenama,no_siri FROM DAFTARHARTASH01 WHERE no_siri =' " & nilai & " ' "
there is an extra space around in the where clause.

change above line with

strSQL="SELECT no_harta1,jenama,no_siri FROM DAFTARHARTASH01 WHERE no_siri ='" & nilai & "' "


 
 
0
 
eez81Author Commented:
TO appari
it's work better now...

if u see the code below,an output show all the data which have a alphabetic 'z'. my problem is,i just want to display data which first word start with 'z'.
<%
'########## DSN-less connections ############################################################################################
Dim DBName, objConn, rs, strSQL      '//Variables we need
DBName = server.mappath("spick98.mdb")'//Database file !CHANGE IF NEEDED!

'//Create ADO connection
Set objConn = Server.CreateObject("ADODB.Connection")

'//Open our student database with this string
objConn.ConnectionString = "DBQ=" & DBName & ";Driver={Microsoft Access Driver (*.mdb)};"

'//Access our database
objConn.Open

'//Create a recordset
Set rs = Server.CreateObject("ADODB.Recordset")
'######################################################################################################

      strSQL = "SELECT * FROM DAFTARHARTASH01 WHERE jenama LIKE'%z%';"
      Set rs= objConn.execute(strSQL)
      bil=0
      response.Write("<br><table border=" & 2 )
      response.Write("<tr><td>Bil.</td><td>Matrik</td><td>Nama</td><td>Mel</td></tr>")

Do While NOT rs.EOF
      bil=bil + 1
      response.Write("<tr><td><b>" & bil & "</b></td>")
      response.Write("<td><b>" & rs("id_no") & "</b></td>")
      response.Write("<td><b>" & rs("jenama")  & "</b></td>")
      response.Write("<td><b>" & rs("no_harta1")  & "</b></td>")
      response.Write("<td><b>" & rs("kod_kumpulan")  & "</b></td>")
      response.Write("<td><b>" & rs("no_siri")  & "</b></td>")      
      response.Write("<td><b>" & rs("lokasi") & "</b></td></tr>")
      
 rs.MoveNext
 Loop
      response.Write("</table border>")
 rs.close
%>
0
 
appariCommented:
change
strSQL = "SELECT * FROM DAFTARHARTASH01 WHERE jenama LIKE'%z%';"

to

strSQL = "SELECT * FROM DAFTARHARTASH01 WHERE jenama LIKE 'z%';"
0
 
eez81Author Commented:
thank you so much..
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now