C#中SQL语句参数写法
OracleConnection oc=new OracleConnection("data source=osserver;User Id=****;password=**");
OracleCommand cmd=new OracleCommand("insert into cym1.PreviousFile (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.PreviousFile (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 PreviousFile (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 PreviousFile (filename) values (@filename)
在定义此参数的参数变量里面参数要写@
SqlParameter sp=new SqlParameter("@filename",SqlDbType.VarChar,256);
补充:软件开发 , C# ,