I am trying to insert data from a form into a SQL Server 2005 database. The only code examples I can find are for Access databases. I am having a problem at the execute command. I have tried three different ways to execute but the page goes to an error page instead of to the submitted form page after the submit button is pressed with all three tries. I left all three different ways I tried it in the code and they are all commented out. Can anyone tell me where I am going wrong with this? Thanks so much:
<%
dim txtFirstname
txtFirstname = Request.Form("txtFirstname")& "<BR /><BR />"
dim txtLastname
txtLastname = Request.Form("txtLastname")& "<BR /><BR />"
dim txtEmail
txtEmail = Request.Form("txtEmail")& "<BR /><BR />"
dim txtPhone
txtPhone = Request.Form("txtPhone")& "<BR /><BR />"
dim txtAddress
txtAddress = Request.Form("txtAddress")& "<BR /><BR />"
dim txtCity
txtCity = Request.Form("txtCity")& "<BR /><BR />"
dim txtState
txtState = Request.Form("txtState")& "<BR /><BR />"
dim txtZipcode
txtZipcode = Request.Form("txtZipcode")& "<BR /><BR />"
dim txtComments
txtComments = Request.Form("txtComments")& "<BR /><BR />"
dim imsg
dim iconf
dim flds
dim strSQL
dim conn
dim comm
dim db
dept = "louise.hogan@lrwu.com"
strSQL = "INSERT INTO Requests (CATEGORY, FIRSTNAME, LASTNAME, EMAIL, PHONE, ADDRESS, CITY, STATE, ZIPCODE, COMMENTS) VALUES ('" & dept & "', '" & txtFirstname & "', '" & txtLastname & "', '" & txtEmail & "', '" & txtPhone & "', '" & txtAddress & "', '" & txtCity & "', '" & txtState & "', '" & txtZipcode & "', '" & txtComments & "');"
set conn = Server.CreateObject("ADODB.Connection")
conn.open "Provider=SQLOLEDB; Data Source = SQL0; Initial Catalog = RequestForm; User Id = formuser; Password= dilbert;"
set comm = server.CreateObject("ADODB.Command")
'With comm
' .activeconnection = conn
' .commandtext = strSQL
'.commandtype = adCmdText
'.execute strSQL
'end with
'set db = conn.Execute(strSQL)
'conn.Execute(strSQL)
conn.close
response.redirect("request.asp?submitted=yes")
%>