C#中SQL語句參數寫法
來源:互聯網
上載者:User
語句 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);