Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginner trying to understand ASP

Status
Not open for further replies.

FurryGorilla

Technical User
Apr 11, 2001
76
0
0
GB
Hi

I'm currently trying to get to grips with an ASP system that is going to implemented shortly.

I've made a reasonable start on it by using the code currently present but now I want to check that a part number exists in access data base table against the part number entered on a web page.

The database is configured correctly as pages leading up to this page work fine. The table is called routing and has fields named part, opno, cell, desc and stdadmin. The database is called routings1. The part number is not necessarily just a number, characters may also be present.

The code I currently have is as follows but I get an error message pointing to the last line in the code below.

<% inp = request(&quot;cellinput&quot;)*1%>
<%
Query=&quot;Select * from routing where part = &quot;
Query=Query&request(&quot;part&quot;)
%>
<%
'Create a connection object
Set cn = Server.CreateObject(&quot;ADODB.Connection&quot;)
'Open a connection; the string refers to the DSN
cn.Open &quot;routings&quot;
Set RSlist =Server.CreateObject(&quot;ADODB.recordset&quot;)
%>
<%RSlist.Open Query,cn,1%>

Any help would be appreciated.

Thanks in advance
Chris
 
This script should work for you without any changes, although you will probably want to tweak it a bit. One note for you is this: Avoid using multiple ASP delimiters within a script, as it forces the server to work harder. If you can, keep all your ASP in one or two code blocks.

Code:
<%

	strQuery = Trim( Request( &quot;part&quot; ) )
	If Len( strQuery ) > 0 Then
		Set Con = Server.CreateObject( &quot;ADODB.Connection&quot; )
		Con.Open( &quot;routing&quot; )
		If Con.State > 0 Then
			Set Rec = Server.CreateObject( &quot;ADODB.RecordSet&quot; )
			Rec.Open &quot;SELECT * FROM routing WHERE part=&quot; & Chr(39) & strQuery & Chr(39), Con
			If Rec.EOF Then Response.Write( &quot;No parts found for <i>&quot; & strQuery & &quot;</i>&quot; )
			If Not Rec.EOF Then
				Response.Write( &quot;<table cellpadding=3 cellspacing=0 border=1>&quot; & vbNewLine & &quot;<tr>&quot; & vbNewLine )
				For Idx = 0 To Rec.Fields.Count - 1
					Response.Write( vbTab & &quot;<td align=center>&quot; & Rec.Fields(Idx).Name & &quot;</td>&quot; & vbNewLine )
				Next
				Response.Write( &quot;</tr>&quot; & vbNewLine )
				While Not Rec.EOF
					Response.Write( &quot;<tr>&quot; & vbNewLine )
					For Idx = 0 To Rec.Fields.Count - 1
						Response.Write( vbTab & &quot;<td align=left>&quot; & Rec.Fields(Idx).Value & &quot;</td>&quot; & vbNewLine )
					Next
					Response.Write( &quot;</tr>&quot; & vbNewLine )
					Rec.MoveNext
				Wend
				Response.Write( &quot;</table>&quot; )
			End If
			Rec.Close : Set Rec = Nothing
		Else
			Response.Write( &quot;Unable to open database connection&quot; )
		End If
		Con.Close : Set Con = Nothing
	Else
		Response.Write( &quot;No query has been specified&quot; )
	End If

%>

ACK! - This forum forces my code to wrap, makes it harder to read, but you can probably follow it. James Lindën
 
<%
Query=&quot;Select * from routing where part = &quot;
Query=Query&request(&quot;part&quot;)
%>

If your query has numeric AND text you need to enclose it with single quotes:

<%
Query=&quot;Select * from routing where part = &quot;
Query=Query & &quot;'&quot; & request(&quot;part&quot;) & &quot;'&quot;
%>
Since the quotes look confusing here is a sample out-put and text description of the quotes:
Select * from routing where part = '123ABC123'
&quot;'&quot; = Double Quote(&quot;), Single Quote('), Double Quote(&quot;)

Also, if you are just seeing if the part exists in the Database, you should try not to do the &quot;select *&quot;. Try &quot;select idPart&quot; (or whatever your part id is) - the &quot;overhead&quot; is less.

Just trying to help when I can! :eek:) =====================
Dennis B
 
Thanks for your help. I'm finding it pretty tough going without having any references but your posts were really helpful.

I'm going to have a look through your code James to see if I can understand it a bit more but it's great.

Thanks Dennis for your post. Don't worry I do need the * in the query :).

Thanks once again
Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top