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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing an ASP variable to a database using SQL

Status
Not open for further replies.

telcogirl

Technical User
Aug 26, 2002
37
US
I created an ASP page that will generate a random number. I have a variable set to catch the number. now, i want to pass that variable to a field in my database using a SQL statement, INSERT INTO......I am also passing data from a form into my database using Reqest.Form("LastName"). My code looks like this:

mySQL= "INSERT INTO PreApprovalDetail "

mySQL= mySQL & "(PreApproval#,LastName,FirstName,CurrOrg,CurrBldg,CurrRoom,NewOrg,NewBldg,NewFloor,NewRoom) "
mySQL= mySQL & "VALUES ('" & "PreApp" & "','"
mySQL= mySQL & request.form("LastName") & "','"
mySQL= mySQL & request.form("FirstName") & "','"
mySQL= mySQL & request.form("CurrOrg") & "','"
mySQL= mySQL & request.form("CurrBldg") & "','"
mySQL= mySQL & request.form("CurrRoom") & "','"
mySQL= mySQL & request.form("NewOrg") & "','"
mySQL= mySQL & request.form("NewBldg") & "','"
mySQL= mySQL & request.form("NewFloor") & "','"
mySQL= mySQL & request.form("NewRoom") & "')"
myConnection.Execute(mySQL)

It works ok, until i want to insert that PreApp. I am hoping it is a syntax error.

Oh, I should mention that i am NOT a programmer by any means.....just trying to figure out a school project. Any help will be soooo appreciated.......
 
try the following always in cases like this

Dim out the line that executes the query in this instance :

dim myConnection.Execute(mySQL)

And instead put the following line

response.Write &quot;mySQL: &quot; &mySQL&&quot;<br>&quot;

See what you get its the best practice to dim out the thin and find out the nature of the error.

On your case may be various reasons why this is failing, could be inapropriate data type you are trying to insert could be a blank entry. ...

 
Thanks for your help, but now i get this error:

Microsoft VBScript compilation error '800a0411'

Name redefined

/officemoves/email.asp, line 34

dim myConnection.Execute(mySQL)

This could be hopeless............
 
Your inserting a fixed value &quot;PreApp&quot; instead of a variable, also dunno what database but you may need to remove the ' from the number variable

mySQL= mySQL & &quot;VALUES ('&quot; & PreApp & &quot;','&quot;
 
i am trying to connect to an Access database. I tried both with and without the quotes. The problem is my knowledge of this is sketchy.........thanks for the help....
 
Yes, i did........still no dice.......that's ok, i took it out. I will try to figure soemthing else out.....maybe VBA within the DB.......

thanks again
 
sorry i mean REM out not DIM

im idiot

REM is used to rem out what you dont need or you can use the simple &quot; ' &quot;like that:

' myConnection.Execute(mySQL)

or

rem myConnection.Execute(mySQL)

Sorry again.

try this as i said before and also make sure you are not having any other references to any database objects that you previously remmed out so to avoid any other errors.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top