Link to home
Create AccountLog in
Avatar of DILORENZO
DILORENZO

asked on

Why am I getting a Compiler Error Message: BC30451: Name 'tableFieldArray' is not declared and how do I properly declare an array to use in my script?

I want to create a single script to handle all of my DB operations from a flex interface.  All I need to do is store the DB table fields in an array and get the target array to build my sql statements and form variable requests.

I am getting a Compiler Error Message: BC30451: Name 'tableFieldArray' is not declared.  Any ideas?
<%@ Page Language="VB" Debug="true" %>
 
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web" %>
<%
Response.Cache.SetExpires(DateTime.Now.AddSeconds(1))
' kick user off system, stops person from calling aspx directly outside of Flash
Dim ConnString as String  = "My Connection String"
 
Dim action as String = REQUEST.FORM("action")
Dim targetTable as String = REQUEST.FORM("targetTable")
 
Dim updateString as String = ""
Dim dbFields as String = ""
Dim dbFieldValues as String = ""
Dim targetArrayValue as String = ""
'our sql strings
Dim userSQL as String = ""
 
 
 
SELECT CASE targetTable
 
	CASE "isoProcedure"
	
		Dim tableFieldArray() as String = {"ProcedureId","ProcedureNumber","ProcedureTitle","DirectorateId"}
 
			
END SELECT
 
IF action <> "delete" THEN	
	FOR i as integer = 1 to 3
	
		targetArrayValue = trim(request.form(tableFieldArray(i)))
		
		dbFields = dbFields  & tableFieldArray(i) & ","  
		dbFieldValues = dbFieldValues & ",'" &  targetArrayValue & "'"
		updateString = updateString & tableFieldArray(i) & "=" & "'" & targetArrayValue & "',"
					
	NEXT
		updateString = left(updateString, len(updateString)-1)
		dbFields = left(dbFields, len(dbFields)-1)
END IF
 
 
Dim tablePkField as String =  (tableFieldArray(0))
Dim tablePkValue as Integer =  REQUEST.FORM(tableFieldArray(0))
 
Dim userConn As New SqlConnection( ConnString )
userConn.Open()
 
SELECT CASE action
CASE "insert"
userSQL = "INSERT INTO " & targetTable & " (" & dbFields & ") values (" & dbFieldValues & ");"
 
CASE "update"
userSQL = "UPDATE " & targetTable & " SET " & updateString & " WHERE " & tablePkField & " = '" & tablePkValue & "';"
 
CASE "delete"
userSQL = "DELETE FROM " & targetTable & " WHERE " & tablePkField & " = '" & tablePkValue & "';"
 
END SELECT
 
Dim userCommand As New SqlCommand(userSQL, userConn)
userCommand.ExecuteNonQuery()
 
%>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of thecodist
thecodist
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Actually you should also set the array to an empty set to initialize it:

Dim tableFieldArray() As String = {}

SELECT CASE targetTable
      CASE "isoProcedure"
            tableFieldArray = Split("ProcedureId,ProcedureNumber,ProcedureTitle,DirectorateId", ",")
END SELECT
Here's another way of re-loading your array contents in your CASE block:

Dim tableFieldArray() As String = {}

SELECT CASE targetTable
      CASE "isoProcedure"
            tableFieldArray = New String() {"ProcedureId","ProcedureNumber","ProcedureTitle","DirectorateId"}
END SELECT
the reason why you are getting an error when you use this syntax:

SELECT CASE targetTable
 
      CASE "isoProcedure"
      
            Dim tableFieldArray() as String = {"ProcedureId","ProcedureNumber","ProcedureTitle","DirectorateId"}
 
                  
END SELECT


is that the statement

Dim tableFieldArray() as String = {"ProcedureId","ProcedureNumber","ProcedureTitle","DirectorateId"}

is 'in scope' and thus defined, ONLY within the Select...End Select Block.  Once the code passes beyond that Block, the variable is no longer defined.  Also, why are you using a Select block in order to declare and define this variable?

If the TargetTable value will ALWAYS, in every possible case, be "isoProcedure"
then the Select Case...End Select accomplishes nothing, and you should simple eliminate that Select...End Select block, and use the statement

Dim tableFieldArray() as String = {"ProcedureId","ProcedureNumber","ProcedureTitle","DirectorateId"}

without the SELECT ... END SELECT block.

AW