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

ASP insert to SQL Server database 1

Status
Not open for further replies.

JGresko

Programmer
Apr 24, 2002
86
US
I'm attempting to insert a record to a SQL Server database from an ASP webpage. I'm having trouble determining the best method to use to do this. My MSDN help files seem to be on vacation because they're not giving me what I need today.

Any pointers will be much appreciated!

Thanks, Judy

When I run the code below I get the following error:

Error#: 424 - Object required
Thatexplainsit.html database insert failed.



'open a database connection
Code:
strDSN = Application("FileExchange_ConnectionString")
 Set conn = Server.CreateObject("ADODB.Connection")	
 conn.Open strDSN

'Create a command object
Code:
Dim cmd
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = conn
cmd.CommandTimeout = 15
cmd.CommandType = adCmdText
'Create the Insert SQL
Code:
tsql = "INSERT INTO FileCheck (id, Path, Document, UserName, CreateDate) VALUES (NEWID(),'" & Dir & "','" & newfilename0 & "','" & session("User") & "', GETDATE())"

cmd.CommandText = tsql
cmd.Execute
'Catch Errors
Code:
if Err <> 0 Then 
     errtext = &quot;Error#: &quot; & err & &quot; - &quot; & err.description
     & &quot;<BR>&quot; & newfilename0 & &quot; database insert failed.&quot;
End If
 
Before I get into this too far....

&quot;Thatexplainsit.html database insert failed.&quot;

Is this page's extension &quot;.html&quot;? It should be &quot;.asp&quot; for server-side coding.... Get the Best Answers! faq333-2924
Merry Christmas!
mikewolf@tst-us.com
[angel][santa][elf][reindeer][santa2]
 
This code is part of a file upload system.
&quot;Thatexplainsit.html&quot; is just a test document I was using.

The name of the uploaded file is just a text string and doesn't inpact the code at all.

:)
 
What uis this doibng in your sql statement?
NEWID()

-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
try changing:
Set cmd = New ADODB.Command

to:
Set cmd = Server.CreateObject(&quot;ADODB.command&quot;) Get the Best Answers! faq333-2924
Merry Christmas!
mikewolf@tst-us.com
[angel][santa][elf][reindeer][santa2]
 
ya, looks like a sub procedue/function call in there. hmm.. not going to work possibly? ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
Nice catch
-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 

Thank you mwolf00 ! That was my problem!

Happy Holidays
[santa3]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top