473,809 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieve data value in asp based on form Value

4 New Member
Hi all,

I need your help to retrieve data value from my MS Access database based on the criteria.

I have a database named distance in which i have made a table called cities and made 3 fields naming..City_fr om, City_To and Distance_KM

Now I want asp to find distance value from the datatable based on information given in City From and City To field

If value not found returned to "No Record Found"

Please help how can I do so...

I will be very very grateful for your prompt response.

Regards
Yogeshwar Vats
Nov 21 '09 #1
4 2418
jeffstl
432 Recognized Expert Contributor
select Distance_KM from distance where City_from = '" & txtCityFrom.Tex t & "' and City_To = '" & txtCityTo.Text & "'

That is the sql you want. You will need to set up a form with those names to accept criteria values.
Nov 23 '09 #2
yogeshwarv
4 New Member
Hi jeffstl, thanks it working perfectly

how if i wish to put my result in front of find button

here is the code

<form name="dist" method="POST">
<table>
<tr><td><font size="2" face="Tahoma">C ity From: </font> </td>
<td><input type="text" name="City_From " size="25"></td></tr>
<tr><td><font face="Tahoma" size="2">City To: </font> </td>
<td><input type="text" name="City_To" size="25"></td></tr>
<tr><td>
<font face="Tahoma">
<input type="submit" name="Find" value="Find"></font></td>
<td></td>
</table>
</FORM>

<%
' Declaring variables
Dim RS, count, City_From, City_To, Distance_KM1, data_source, con, KM, check,string

' A Function to check if some field entered by user is empty
Function ChkString(strin g)
If string = "" Then string = ""
ChkString = Replace(string, "'", "''")
End Function

' Receiving values from Form
City_From = ChkString(Reque st.Form("City_F rom"))
City_To = ChkString(Reque st.Form("City_T o"))

If city_from="" OR city_to=False Then

Response.write "<br>"

Else

data_source = "Provider=Micro soft.Jet.OLEDB. 4.0; Data Source=" & _
Server.MapPath( "distance.m db")

' Creating Connection Object and opening the database
Set con = Server.CreateOb ject("ADODB.Con nection")
con.Open data_source

check = "select count(*) as [count] from cities where City_From ='"& Request.Form("C ity_From") & "' AND City_To ='"& Request.Form("C ity_To") & "'"

set RS = Con.Execute(che ck)

if RS("Count") = 0 then
Response.Write "<b>Records Not Found </b>"

Else

KM = "SELECT distance_KM FROM cities " _
& " WHERE city_from = '" & Replace( city_from, "'", "''" ) & "' " _
& " AND city_to = '" & Replace( city_to, "'", "''" ) & "' "

set RS = con.execute(KM)
distance_KM1 = RS("distance_KM ")
RS.close

Con.close

Response.Write "Dist from " & city_from & " to " & city_to & " is " & distance_km1 & " KMs"

end if
end if
%>


pls help
Dec 2 '09 #3
jeffstl
432 Recognized Expert Contributor
I am not sure exactly what you mean. If you mean you are wanting to do the city_From and to you just need to select those values out as well with the distance.

Expand|Select|Wrap|Line Numbers
  1. KM = "SELECT distance_KM,city_from,city_to FROM cities " _
  2. & " WHERE city_from = '" & Replace( city_from, "'", "''" ) & "' " _
  3. & " AND city_to = '" & Replace( city_to, "'", "''" ) & "' "
  4.  
  5. set RS = con.execute(KM)
  6. distance_KM1 = RS("distance_KM")
  7. city_from = RS("city_from")
  8. city_to = RS("city_to")
  9. RS.close
  10.  
Dec 2 '09 #4
yogeshwarv
4 New Member
The script is is running succesfully but i want to detemine the placing of result value into form.

I want to put result value in front of the Find Button. would appreciate your great help

Regards
Yogeshwar
Dec 3 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
7093
by: Vanessa | last post by:
I have a question, is that any other way to retrieve data from another webpage besides using XML object? Because I am using XML object now but give me so much problems. If I used MSXML2.ServerXMLHTTP object, it gives me time out error: msxml3.dll error '80072ee2' The operation timed out If I used Microsoft.XMLHTTP object, it will hang IE!
5
1778
by: Brian Henry | last post by:
Hello, I am working on a simple email website that is kinda like hotmail... but the listing of messages is in a data grid data bound to a table called messages... now one of the columns in the messages data table is called read if the value is 1 the message is read if 0 then unread... what i want to do is show an image in the listing based on that value, if 1 then icn-msg-read.gif will be showed in that column for that message row, if 0...
3
3590
by: Gurpreet22 | last post by:
I have designed a web form, which has a drop down list. What i would like to do is when a user selects a value from the drop down list and submits the form, the user is redirected to the next page, which provides them with further infomation on the selection they have made. I am using asp and an access database. If any one can help it will be greatly appreciated. Thank you
11
2656
by: AishaKhalfan | last post by:
Hi all, I have to populate combo box that retrieve data from database in windows based application. I have two tables which are type and CD. Type has type ID and Category. CD has type ID as foreign key. When I will add a new CD, the user interface for user will show combo box to choose the category from combo box and the selected value should be saved as type ID. First, I did a quarry in type dataset that will do search by type ID. ...
1
3949
by: gudipati | last post by:
hi,i have one problem.actually we can retrieve data from access. what is my requirement is when i retrieve data from access i want to store in text areas. finely,we can store if they r textboxes using "value" attribute.see for sample <input type="text" name="lastName" maxlength="50" size="20" value="<% If (Request("visitationID") <> "") Then response.Write(rstvalues("lastName")) End If %> "></td> but in TextArea we have no option...
12
78038
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please give me some idea where I am going wrong ?? I just want to retrieve data from my emp_mstr table and display it using my JSP file... The table emp_mstr is as follows :- CREATE TABLE EMP_MSTR( EMP_NO VARCHAR(10) PRIMARY KEY, PASSWORD...
4
2802
by: mzmishra | last post by:
I have one webapplication(.net2.0)c#. My page has one dropdownlist which is very huge sometimes it contains many records which is difficult for the users to view the data they exactly looking for. What we want to do now is we want to add a textbox on the top of the dropdown and once user enter any data on textbox we want to select the firstrow in the dropdown which start from the letter they entered in textbox. Can this achieved some...
0
1366
by: lenniekuah | last post by:
Hullo Good Guys, I need your help. Please help me. I am very surprise of this error message: Index was out of range. Must be non-negative and less thatnt he size of the collection. Parameter name :Index I am using C#NET2008 and try to retrieve data from the Clicked Row and it’s not working to my surprised. It has not happened before. This particular problems is because the SQL String retrieve 13 data columns from SQL SERVER Table to fill...
1
5650
by: Nilesh K R | last post by:
hello, I am try to retrieve data from my c# windows application to excel sheet and store this .xls file to desired location. but my problem is that my code save excel file at a predefined location. private Excel.Application m_objExcel = null; private Excel.Workbooks m_objBooks = null; private Excel._Workbook m_objBook = null; private Excel.Sheets m_objSheets = null; private Excel._Worksheet...
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10643
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4333
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.