code not working

Cinnamon
06-17-2002, 10:17 AM
The following code is not working. I have been to several sites (since last Friday) trying to find a solution to my problem. The problem is:

I want a user to be able to enter a record number via the web. And then that record be displayed for editing. For example..
"Enter the record number:"
They enter a number and click SUBMIT and the record displays.

I am new to ASP and am having a hard time with this simple procedure. Here is my code.

code
<html><head>
<TITLE>dbtest.asp</TITLE>
</head>
<body bgcolor="#FFFFFF">

<%
Dim iRecordId
iRecordId=Request.QueryString("unique")
If IsNumeric(iRecordId) Then
iRecordId=CLng(iRecordId)
Else
iRecordId=1
End If

' displays a database in table form via GetRows
myDSN="DSN=database.dsn;server=DIGITAL;database=gen_cards_sql;uid=cinnamon;pw d=sinnamon"
mySQL="SELECT * FROM Cards WHERE [Unique]=" & iRecordId &";"
code



The SELECT lines works great if I type it like this:
mySQL="SELECT * FROM Cards WHERE [Unique]=1000"
It gets record number 1000 and displays it. But if I try to use a variable it doesn't work.

Thank you,
Cinnamon

Serevinus
06-17-2002, 10:53 AM
Sorry for using a DSNless connection but I never use DSN's


<%
Dim SearchThis
SearchThis = Request.QueryString("rid")

If SearchThis <> "" AND IsNumeric(SearchThis) Then
Int(SearchThis)

Dim cnnDatabase, rstDatabase, dtbDatabase
cnnDatabase = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.Mappath("temp.mdb") & ";"
Set rstDatabase = Server.CreateObject("ADODB.Recordset")
dtbDatabase = "SELECT rID,Data FROM TempTable WHERE rID=" & SearchThis & ";"
rstDatabase.Open dtbDatabase, cnnDatabase, 3, 3, 1

If NOT rstDatabase.EOF Then
Response.Write "rID = " & rstDatabase.Fields("rID") & "<BR>"
Response.Write "Data = " & rstDatabase.Fields("Data")
Else
Response.Write "Record not found"
End If

rstDatabase.Close
Set rstDatabase = Nothing
Else
Response.Write "Invalid input"
End If
%>

Robby
06-17-2002, 11:12 AM
Try...

mySQL="SELECT * FROM Cards WHERE [Unique]=" & iRecordId

Cinnamon
06-17-2002, 01:24 PM
Ok it's getting closer. I now have two ASP files (see below). After I input the record number and click submit I get my error message of "Invalid Input". Can someone please tell what I'm doing wrong?

Thanks,
Cinnamon

new_page_1.asp
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body>

<form action="new_page_2.asp" method="get">
Enter record number:
<input type="text" name="iRecordId"><br><br>
<input type="submit" value="Submit">
</form>

</body>

</html>


new_page_2.asp
html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 2</title>
</head>

<body>
<%
Dim SearchThis
SearchThis = Request.QueryString("iRecordId")

If SearchThis <> "" AND IsNumeric(SearchThis) Then
Int(SearchThis)

Dim cnnDatabase, rstDatabase, dtbDatabase
cnnDatabase = "Provider={SQL Server};server=DIGITAL;database=gen_cards_sql;uid=cinnamon;pwd=sinnamo n"
Set rstDatabase = Server.CreateObject("ADODB.Recordset")
dtbDatabase = "SELECT unique,cardpath FROM Cards WHERE unique=" & SearchThis & ";"
rstDatabase.Open dtbDatabase, cnnDatabase, 3, 3, 1

If NOT rstDatabase.EOF Then
Response.Write "record = " & rstDatabase.Fields("unique") & "<BR>"
Response.Write "cardpath = " & rstDatabase.Fields("cardpath")
Else
Response.Write "Record not found"
End If

rstDatabase.Close
Set rstDatabase = Nothing
Else
Response.Write "Invalid input"
End If
%>




</body>

</html>

Robby
06-17-2002, 01:29 PM
This line...
If SearchThis <> "" AND IsNumeric(SearchThis) Then

= Not good.

if it's numeric then it can't be blank, so try this....


If IsNumeric(SearchThis) Then

Robby
06-17-2002, 01:33 PM
Oh, I noticed you didn't remove the semicolon at the end of the Select....


and get rid of this line Int(SearchThis), do the cast at the end of the Select...

dtbDatabase = "SELECT unique,cardpath FROM Cards WHERE unique=" & clng(SearchThis)

btw, you don't really need to cast. ie clng() or cint()

Cinnamon
06-17-2002, 03:22 PM
Ok on to the next problem. Slowly but surely I'm getting there with your help!

Here is the new and improved code...

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 2</title>
</head>

<body>
<%
Dim SearchThis
SearchThis = Request.QueryString("iRecordId")

If IsNumeric(SearchThis) Then

Dim cnnDatabase, rstDatabase, dtbDatabase
cnnDatabase = "Driver=SQL Server;server=DIGITAL;database=gen_cards_sql;uid=cinnamon;pwd=sinnamon"
Set rstDatabase=Server.CreateObject("ADODB.Recordset")
dtbDatabase = "SELECT unique,cardpath FROM Cards WHERE unique"=SearchThis
rstDatabase.Open dtbDatabase, cnnDatabase, adOpenStatic

If NOT rstDatabase.EOF Then
Response.Write "record = " & rstDatabase.Fields("unique") & "<BR>"
Response.Write "cardpath = " & rstDatabase.Fields("cardpath")
Else
Response.Write "Record not found"
End If

rstDatabase.Close
Set rstDatabase = Nothing
Else
Response.Write "Invalid input"
End If
%>

</body>

</html>


Now I'm at getting the following error:

ADODB.Recordset error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/myweb/new_page_2.asp, line 21



I've looked and looked to try and figure out the solution and I'm lost. I believe that it has to do this line:
Set rstDatabase=Server.CreateObject("ADODB.Recordset")

Am I on the right track and how to fix this!?
Thanks again,

Cinnamon

Robby
06-17-2002, 05:44 PM
You should really copy/paste from the replies, becuase sometime there are single-quotes next to double-quotes within th solution. ok, not in this case....

dtbDatabase = "SELECT unique,cardpath FROM Cards WHERE unique=" & SearchThis


you had done it like this...

dtbDatabase = "SELECT unique,cardpath FROM Cards WHERE unique"=SearchThis

Cinnamon
06-18-2002, 08:07 AM
Thanks for all of the help. Things are working great thus far. However, it's a pretty big project so I'm sure you'll hear from me again soon!

Cinnamon

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum