将图像/文件插入Oracle数据库 [英] insert image/file into oracle database
本文介绍了将图像/文件插入Oracle数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里粘贴我的代码.上传时出现以下错误:
在处理命令期间发生一个或多个错误. ORA-00936:缺少表达式.文件成功上传
Here I am pasting my code. While uploading I am getting error as:
One or more errors occurred during processing of command. ORA-00936: missing expression. File Uploaded Successfully
private Boolean InsertUpdateData(OleDbCommand cmd)
{
string myConnection = "Provider=msdaora;User Id=sudhir;Password=sudhir;";
OleDbConnection myConn = new OleDbConnection(myConnection);
cmd.Connection = myConn;
try
{
myConn.Open();
cmd.ExecuteNonQuery();
return true;
}
catch (Exception ex)
{
Response.Write(ex.Message);
return false;
}
finally
{
myConn.Close();
myConn.Dispose();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
// Read the file and convert it to Byte Array
string filePath = FileUpload1.PostedFile.FileName;
string filename = Path.GetFileName(filePath);
string ext = Path.GetExtension(filename);
string contenttype = String.Empty;
//Set the contenttype based on File Extension
switch(ext)
{
case ".doc":
contenttype = "application/vnd.ms-word";
break;
case ".docx":
contenttype = "application/vnd.ms-word";
break;
case ".xls":
contenttype = "application/vnd.ms-excel";
break;
case ".xlsx":
contenttype = "application/vnd.ms-excel";
break;
case ".jpg":
contenttype = "image/jpg";
break;
case ".png":
contenttype = "image/png";
break;
case ".gif":
contenttype = "image/gif";
break;
case ".pdf":
contenttype = "application/pdf";
break;
}
if (contenttype != String.Empty)
{
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
//insert the file into database
string stryCmd = "INSERT INTO photo(id,name,contenttype,data) values ('1',@Name,@ContentType,@Data)";
OleDbCommand cmd = new OleDbCommand(stryCmd);
cmd.Parameters.Add("@name", OleDbType.VarChar).Value = filename;
cmd.Parameters.Add("@contenttype", OleDbType.VarChar).Value = contenttype;
cmd.Parameters.Add("@data", OleDbType.Binary,bytes.Length).Value = bytes;
InsertUpdateData(cmd);
Label1.ForeColor = System.Drawing.Color.Green;
Label1.Text = "File Uploaded Successfully";
}
else
{
Label1.ForeColor = System.Drawing.Color.Red;
Label1.Text = "File format not recognised. Upload Image/Word/PDF/Excel formats";
}
}
推荐答案
可能在这里:
将照片(id,名称,内容类型,数据)插入值("1",@ Name,@ ContentType,:Data);
您给了:Data而不是@Data.
Might be here:
"INSERT INTO photo(id,name,contenttype,data) values (''1'',@Name,@ContentType,:Data)";
You have given :Data instead of @Data.
这篇关于将图像/文件插入Oracle数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文