Forums

This topic is locked

Database problem: Dim MM_editCmd

Posted 09 Nov 2007 13:44:43
1
has voted
09 Nov 2007 13:44:43 James Chan posted:
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/connform.asp" -->
<%
Dim MM_editAction
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
Dim MM_abortEdit
MM_abortEdit = false
%>
<%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
If condition = "" Then
MM_IIf = ifFalse
Else
MM_IIf = ifTrue
End If
End Function
%>
<%
If (CStr(Request("MM_insert") = "form" Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd

Set MM_editCmd = Server.CreateObject ("ADODB.Command"
MM_editCmd.ActiveConnection = MM_connform_STRING
MM_editCmd.CommandText = "INSERT INTO [form] ([CLASS], COUNTRY, [STATE/PROVINCE], CITY, POSTAL, [DATE], [TIME], CNAME, CPHONE, EMAIL) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 201, 1, -1, Request.Form("Fitness Class") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 201, 1, -1, Request.Form("Country") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 201, 1, -1, Request.Form("State/Province") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 201, 1, -1, Request.Form("City") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 201, 1, -1, Request.Form("Postal Code") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 135, 1, -1, MM_IIF(Request.Form("Date", Request.Form("Date", null)) ' adDBTimeStamp
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 135, 1, -1, MM_IIF(Request.Form("Time", Request.Form("Time", null)) ' adDBTimeStamp
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 201, 1, -1, Request.Form("Contact Name") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9", 5, 1, -1, MM_IIF(Request.Form("Contact #", Request.Form("Contact #", null)) ' adDouble
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param10", 201, 1, -1, Request.Form("Email") ' adLongVarChar
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

' append the query string to the redirect URL
Dim MM_editRedirectUrl
MM_editRedirectUrl = "classadded.asp"
If (Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
Response.Redirect(MM_editRedirectUrl)
End If
End If
%>
<%
Dim rsform
Dim rsform_cmd
Dim rsform_numRows

Set rsform_cmd = Server.CreateObject ("ADODB.Command"
rsform_cmd.ActiveConnection = MM_connform_STRING
rsform_cmd.CommandText = "SELECT * FROM form ORDER BY ID ASC"
rsform_cmd.Prepared = true

Set rsform = rsform_cmd.Execute
rsform_numRows = 0
%>
<%
If (CStr(Request("MM_insert") = "form" Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd

Set MM_editCmd = Server.CreateObject ("ADODB.Command"
MM_editCmd.ActiveConnection = MM_form_STRING
MM_editCmd.CommandText = "INSERT INTO [form] ([CLASS], COUNTRY, [STATE/PROVINCE], CITY, POSTAL, [DATE], [TIME], CNAME, CPHONE, EMAIL) VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 201, 1, -1, Request.Form("Fitness Class") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 201, 1, -1, Request.Form("Country") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 201, 1, -1, Request.Form("State/Province") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 201, 1, -1, Request.Form("City") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 201, 1, -1, Request.Form("Postal Code") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 135, 1, -1, MM_IIF(Request.Form("Date", Request.Form("Date", null)) ' adDBTimeStamp
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 135, 1, -1, MM_IIF(Request.Form("Time", Request.Form("Time", null)) ' adDBTimeStamp
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 201, 1, -1, Request.Form("Contact Name") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9", 5, 1, -1, MM_IIF(Request.Form("Contact #", Request.Form("Contact #", null)) ' adDouble
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param10", 201, 1, -1, Request.Form("Email") ' adLongVarChar
' MM_editCmd.Execute
response.Write(MM_editCmd)

MM_editCmd.ActiveConnection.Close

' append the query string to the redirect URL
Dim MM_editRedirectUrl
MM_editRedirectUrl = "/classadded.asp"
If (Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
Response.Redirect(MM_editRedirectUrl)
End If
End If
%>

<%

Set Command1 = Server.CreateObject ("ADODB.Command"
Command1.ActiveConnection = "Driver={Microsoft Access Driver (*.mdb)};Dbq=d:\the correct info is here
Command1.CommandText = "select * from form"
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()

%&gt;<font color=red></font id=red><u></u>

what do i do? Name Redefined?

Replies

Replied 10 Nov 2007 20:41:06
10 Nov 2007 20:41:06 Justin Sir replied:
Your code is calling on two connections. form and connform. You have the connection #include for connform but not one for form. I see you have some code which looks like a connection string but 1) you don't identify it or dim it as form and 2)you have created it AFTER the code that calls on it.

Coding is a lot like reading, you start at the top and logically place code so it builds a story. In your case you have the plot before you set the stage.
Replied 11 Nov 2007 01:03:01
11 Nov 2007 01:03:01 James Chan replied:
thanks
will try to fix!

Reply to this topic