When using Oracleparameters, the parameters in CommandText must begin with ":" and cannot contain special characters such as @. When you reference this parameter elsewhere, you do not have to add ":", and the program automatically adds ":" to it.
OracleCommand oracmd = Oracon. CreateCommand ();
Oracmd. CommandText = "Select Gas_user_no,vol_page,user_name,user_address,unit from gas_meter where gas_user_no =: Gas_userno";
if (!oracmd. Parameters.contains ("Gas_userno"))
{
Oracmd. Parameters.Add (New OracleParameter ("Gas_userno", Oracledbtype.varchar2, ParameterDirection.Input));
}
Oracmd. parameters["Gas_userno"]. Value = "666666"
OracleDataAdapter da = new OracleDataAdapter ();
Da. SelectCommand = Oracmd;
DataTable dt = new DataTable ();
Da. Fill (DT);
OracleDataReader dr = Oracmd. ExecuteReader ();
The following contents are reproduced:
When the CommandType property is set to StoredProcedure, the CommandText property should be set to the name of the stored procedure. if the stored procedure name contains any special characters, the user may be required to use escape character syntax. The command executes this stored procedure when one of the Execute methods is called.
The. NET Framework data Provider for Oracle does not support a question mark (?) placeholder when passing parameters to an SQL statement that is called by CommandType.Text's OracleCommand. in this case, you must use a named parameter. For example:
Copy code example
The following example creates a OracleCommand and displays its parameters. to complete this task, pass a oracleconnection, a query string (which is an SQL SELECT statement), and an array of OracleParameter objects to the method.
Public voidCreateoraclecommand (oracleconnection connection,stringqueryString, oracleparameter[] myparamarray) {OracleCommand command=NewOracleCommand (queryString, connection); Command.commandtext="SELECT * from Emp WHERE job =:p job and sal =:p sal"; for(intj =0; J < Myparamarray.length; J + +) command. Parameters.Add (Myparamarray[j]); stringMessage =""; for(inti =0; I < command. Parameters.count; i++) Message+ = command. Parameters[i]. ToString () +"\ n"; Console.WriteLine (message); using(OracleDataReader row =command. ExecuteReader ()) { while(row. Read ()) {Console.WriteLine (row. GetValue (0)); } } }
Use of OracleParameter (parameter name to begin with: Do not allow special characters such as @) [go]