Solved

data from database not appears...

Posted on 2003-12-01
4
316 Views
Last Modified: 2006-11-17
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
Comment
Question by:eez81
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:appari
ID: 9855885
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
 

Author Comment

by:eez81
ID: 9856184
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
 
LVL 39

Accepted Solution

by:
appari earned 25 total points
ID: 9856336
change
strSQL = "SELECT * FROM DAFTARHARTASH01 WHERE jenama LIKE'%z%';"

to

strSQL = "SELECT * FROM DAFTARHARTASH01 WHERE jenama LIKE 'z%';"
0
 

Author Comment

by:eez81
ID: 9856492
thank you so much..
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VFP9 options in the cloud (and elsewhere) 3 116
Database restore 8 68
oracle query help 29 64
microsoft access question 8 46
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Creating and Managing Databases with phpMyAdmin in cPanel.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now