我尝试读取blob并将其发送为byte[]。这是我使用的方法。
public byte[] getBlob(long blobId)
{
OracleCommand cmd = new OracleCommand();
cmd.Connection = _connection;
cmd.CommandText = "select TBlob_file FROM Tblob where blobId= " + blobId;
object obj = cmd.ExecuteScalar();
if (obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}
我得到了答案,但格式不好。我的答案看起来像:
<base64Binary>AAEAAAD/////AQAAAAAAAAAPAQAAAIFqBgAC/9j/4AAQSkZJRgABAQEASABIAAD/ .......
总是从AAEAAAD/////AQAAAAAAAAAPAQ
开始,我认为这是个问题。也许我并没有按正确的方式转换字节[]中的blob?
Thanx
这是我的字符串到字节数组转换方法(必须先将obj
转换为字符串):
public static byte[] StringToByteArray(string hex)
{
int numberChars = hex.Length;
var bytes = new byte[numberChars / 2];
for (int i = 0; i < numberChars; i += 2)
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
return bytes;
}
此外,请阅读有关sql注入攻击的信息,您可以从这里开始:http://blog.codinghorror.com/give-me-parameterized-sql-or-give-me-death/.您必须使用参数,而不仅仅是字符串串联。