C#中SQL语句参数写法
2024-07-21 02:18:18
供稿:网友
oracleconnection oc=new oracleconnection("data source=osserver;user id=****;password=**");
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();
在oracle中,sql语句参数是:+参数名,
insert into cym1.uploadfile (filename,filecontent) values (:filename,:filecontent)
在定义此参数的参数变量里面参数名不用写:
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();
在sqlserver中,sql语句参数是@+参数名,
insert into uploadfile (filename) values (@filename)
在定义此参数的参数变量里面参数要写@
sqlparameter sp=new sqlparameter("@filename",sqldbtype.varchar,256);
本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。