Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Conditional object dimension
Message
 
À
18/02/2003 13:42:38
Rex Mahel
Realm Software, Llc
Ohio, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00754495
Message ID:
00754618
Vues:
26
Have you tried tracing this code? See if the variable is getting created and what the state of it is when you get to the Try block.

>Cathi,
>
>I have the following code:
>
>
>Sub btn_chgpwd(ByVal s As Object, ByVal e As EventArgs)
>	If IsValid Then
>		myConnection = New OracleConnection(odh)
>		myConnection.Open()
>		myTrans = myConnection.BeginTransaction()
>		myCommand = myConnection.CreateCommand()
>		With myCommand
>			.CommandText = "pkg_users.UPDATE_USERS_QUESTION"
>			.CommandType = CommandType.StoredProcedure
>			.Transaction = myTrans
>			Dim P_USER_ID, P_USER_QUESTION, P_ANSWER, P_MODIFIED_BY, P_ERROR_ID, P_ERROR_MSG As OracleParameter
>			With .Parameters
>				P_USER_ID = .Add("@P_USER_ID", OracleType.VarChar, 10)
>				P_USER_ID.Value = Session("UserName")
>
>				P_USER_QUESTION = .Add("@P_USER_QUESTION", OracleType.VarChar, 120)
>				P_USER_QUESTION.Value = txtnewpassword.Text
>
>				P_ANSWER = .Add("@P_ANSWER", OracleType.VarChar, 60)
>				P_ANSWER.Value = txtrenewpassword.Text
>
>				P_MODIFIED_BY = .Add("@P_MODIFIED_BY", OracleType.VarChar, 10)
>				P_MODIFIED_BY.Value = Session("UserName")
>
>				P_ERROR_ID = .Add("@P_ERROR_ID", OracleType.Double)
>				P_ERROR_ID.Direction = ParameterDirection.Output
>
>				P_ERROR_MSG = .Add("@P_ERROR_MSG", OracleType.VarChar, 100)
>				P_ERROR_MSG.Direction = ParameterDirection.Output
>			End With
>		End With
>
>		Try
>			myCommand.ExecuteNonQuery()
>
>			If P_ERROR_ID.Value = 0 Then
>				Response.Write("before commit")
>				myTrans.Commit()
>				myConnection.Close()
>				Response.Redirect("/login/menu.aspx")
>			Else
>				myTrans.Commit()
>				myConnection.Close()
>			End If
>		Catch eex As Exception
>			Response.Write(eex.ToString())
>			myTrans.Rollback()
>			myConnection.Close()
>		End Try
>	End If
>End Sub
>
>
>
>In the TRY block above, the P_ERROR_ID.Value line give the following error:
>
> Name 'P_ERROR_ID' is not declared.
>
>and all this procedure is under the IF statement. If I move the DIM statement outside the loop, no error occurs.
>
>Is there another way to do this?
>
>
>Thanks
>
>Rex
>
>
>
>
>>Hi Rex,
>>
>>I would recommend tracing through this code in the debugger and see if ConPubs is ever created in the If statement.
>>
>>>All,
>>>
>>>I have a codebehind file that I want to be able to use either the OleDb or Oracle data providers. I have created a strProvider variable and use If statements to dimension Connections, Commands, etc for both Oracle and Oledb. After dimensioning the objects, I try to open the connection outside the if statement, since the connection object is created by that time, but the compiler says the object is undefined.
>>>
>>>
>>>Dim strProvider As String = "OracleClient"
>>>
>>>If strProvider = "OracleClient"
>>>	Dim ConPubs As New OracleConnection(odh)
>>>Else
>>>	Dim ConPubs As New OleDbConnection(odh)
>>>End If
>>>
>>>ConPubs.Open()
>>>
>>>
>>>Is there a way to set this so I can conditionally create an object and use them?
>>>
>>>Thanks
>>>
>>>Rex
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform