[英]Why am I getting ORA-00936 error while trying to save picture in Oracle?
我将尝试将图片插入Oracle数据库-但不起作用
(SQL Server工作中的相同代码非常出色)
string sampleImage = PicNativ;
BinaryReader sampleBR = null;
FileStream sampleFS = null;
OracleConnection sampleConnection = null;
OracleCommand sampleCommand = null;
FileInfo sampleFI = null;
byte[] sampleArr = null;
try
{
if (EDIT_M == 1)
Oracle = "update Sex set Name = '" + txtC.Text.Trim() +
"',pic = @p_pic where ID like '" + txtC4.Text.Trim() + "'";
else
Oracle = "insert into Sex (Id,Code,Name,pic) values "+
"(Sex_Code.nextval,'" + txtA.Text.Trim() + "','" +
txtC.Text.Trim() + "', @p_pic )";
sampleFI = new FileInfo(sampleImage);
sampleFS = new FileStream(sampleImage, FileMode.Open, FileAccess.Read);
sampleBR = new BinaryReader(sampleFS);
sampleArr = sampleBR.ReadBytes((int)sampleFI.Length);
using (sampleConnection = new OracleConnection(Conect))
{
sampleConnection.Open();
using (sampleCommand = new OracleCommand())
{
sampleCommand.Connection = sampleConnection;
sampleCommand.CommandText = Oracle;
sampleCommand.Parameters.
Add("@p_pic", OracleDbType.Blob ).Value = sampleArr;
sampleCommand.ExecuteNonQuery();
}
}
}
finally
{
sampleBR.Close();
sampleFS.Close();
}
如您所知, ORA-00936是缺少表达式错误。 在您的问题代码中,您正在SQL语句中使用绑定变量。 在Oracle中, 占位符变量以冒号开头 。 因此,在具有@p_pic
的位置,正确的格式是:@p_pic
。
Microsoft SQL Server是您的命名参数中使用&符的工具。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.