Use of OracleParameter (parameter name to begin with: Do not allow special characters such as @) [go]

Source: Internet
Author: User
Tags oracleconnection

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]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.