Writing SQL statement parameters in C #

Source: Internet
Author: User
Tags insert oracleconnection
Statement OracleConnection oc=new oracleconnection ("Data source=osserver; User id=****;p assword=** ");
OracleCommand cmd=new OracleCommand ("INSERT into Cym1.uploadfile (filename,filecontent) VALUES (: filename,: filecontent) ", OC);
OracleParameter op1=new oracleparameter ("filename", oracletype.varchar,256);
OracleParameter op2=new OracleParameter ("Filecontent", Oracletype.blob,filedata. Length);
Op1. Value=system.io.path.getfilename (File1.value);
Cmd. Parameters.Add (OP1);
Op2. Value=filedata;
Cmd. Parameters.Add (OP2);
Oc. Open ();
Cmd. ExecuteNonQuery ();
Oc. Close ();

In Oracle, the SQL statement parameter is: + parameter name,
Insert into Cym1.uploadfile (filename,filecontent) VALUES (: filename,:filecontent)
The parameter name in the argument variable that defines this parameter does not need to be written:
OracleParameter op1=new oracleparameter ("filename", oracletype.varchar,256);


SqlConnection conn=new SqlConnection ("Data source=ccserver;user id=sa;password=****;initial catalog=cym1");
SqlCommand cmd =new SqlCommand ("INSERT into uploadfile (filename) VALUES (@filename)", conn);
SqlParameter sp=new SqlParameter ("@filename", sqldbtype.varchar,256);
Sp. Value= "1.jpg";
Conn. Open ();
Cmd. ExecuteNonQuery ();
Conn. Close ();
SQL statement parameters are @+ parameter names in SQL Server.
INSERT into uploadfile (filename) VALUES (@filename)
In the parameter variable that defines this parameter, the parameter must be written @
SqlParameter sp=new SqlParameter ("@filename", sqldbtype.varchar,256);




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.