//通过Stream读取文件,并转换为byte数组
Stream
stream
=
File.Open(ChoosedFilePaths[i],
FileMode.Open,
FileAccess.Read,
FileShare.Read)
byte[]
buffer
=
new
byte[stream.Length]
stream.Read(buffer,
0,
buffer.Length)
string
constr
=
ConfigurationManager.ConnectionStrings["constr"].ConnectionString
OracleConnection
conn
=
new
OracleConnection(constr)
OracleParameter
param
=
null
OracleCommand
cmd
=
new
OracleCommand()
cmd.Connection
=
conn
cmd.CommandText
=
"insert
into
FJG_FILE_MANAGE(NUMBERS,FILE_NAME,FILECONTENT)
VALUES('"
+
attributes.Number
+
"','"
+
attributes.FileName
+
"',:contents,'")"
param
=
new
OracleParameter("contents",
OracleType.Blob,
buffer.Length)
param.Value
=
buffer
cmd.Parameters.Add(param)
try
{
conn.Open()
cmd.ExecuteNonQuery()
}
catch(System.Exception
e)
{
log.Append("上传状态:t失败!rn"
+
"失败原因:t"
+
e1.Message
+
"rnrn")
}
finally
{
cmd.Close()
}
本来采用的是OleDb,后来测配段滑试发现不好使,好像是Provider的问题,然后改为OracleClient来进行上传,OracleClient不需要Provider。
培腊关键是sql语句中Blob字段的参数要写成“:ParameterName”的形式。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)