[英]Inserting image into VarBinary(max) without SqlParameter
我需要在不使用 SqlParameters 的情况下将图像保存到数据库中。 为什么我需要这样做? 因为我必须使用接口与数据库通信,它只支持原始 SQL。
目前我的插入方法如下所示:
OpenFileDialog dialog = new OpenFileDialog();
dialog.Multiselect = false;
dialog.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp; *.png";
if (dialog.ShowDialog() == DialogResult.OK)
{
byte[] file;
using (var stream = new FileStream(dialog.FileName, FileMode.Open, FileAccess.Read))
{
using (var reader = new BinaryReader(stream))
{
file = reader.ReadBytes((int)stream.Length);
}
}
sql = $"INSERT INTO Table (Image) "
+ $"VALUES (CONVERT(VARBINARY(MAX), '{/* do not know what is supposed to be here exactly*/}'));";
Interface.ExecSQL(sql);
}
感谢您的任何帮助。
我需要在不使用 SqlParameters 的情况下将图像保存到数据库中。 为什么我需要这样做? 因为我必须使用接口与数据库通信,它只支持原始 SQL。
目前我的插入方法如下所示:
OpenFileDialog dialog = new OpenFileDialog();
dialog.Multiselect = false;
dialog.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp; *.png";
if (dialog.ShowDialog() == DialogResult.OK)
{
byte[] file;
using (var stream = new FileStream(dialog.FileName, FileMode.Open, FileAccess.Read))
{
using (var reader = new BinaryReader(stream))
{
file = reader.ReadBytes((int)stream.Length);
}
}
sql = $"INSERT INTO Table (Image) "
+ $"VALUES (CONVERT(VARBINARY(MAX), '{/* do not know what is supposed to be here exactly*/}'));";
Interface.ExecSQL(sql);
}
感谢您的任何帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.