C# 使用c在mysql数据库中插入图像文件#
我正在使用三层体系结构的C#。我必须使用MySQL存储过程插入图像文件。这里我将图像文件转换为字节数组。但是我不能直接插入字节C# 使用c在mysql数据库中插入图像文件#,c#,mysql,asp.net,C#,Mysql,Asp.net,我正在使用三层体系结构的C#。我必须使用MySQL存储过程插入图像文件。这里我将图像文件转换为字节数组。但是我不能直接插入字节 Stream fs = FileUpload1.PostedFile.InputStream; BinaryReader br = new BinaryReader(fs); Byte[] bytes = br.ReadBytes((int)fs.Length); string stbytes = ByteArrayToString(bytes); 因此,我再次将字节
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((int)fs.Length);
string stbytes = ByteArrayToString(bytes);
因此,我再次将字节转换为字符串并插入数据库
public static string ByteArrayToString(byte[] ba)
{
string hex = BitConverter.ToString(ba);
return hex.Replace("-", "");
}
string result = objBL.InsertBankAttachmentBL(filename, contenttype, stbytes); //insert
现在我可以保存word文档了。但我不能插入图像文件。插入图像文件时出现以下异常
第2行“iattach_file”列的数据太长
我的DAC层在这里:
string sqlCommand = "sp_F1_fileUpload";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
// Retrieve products from the specified category.
db.AddInParameter(dbCommand, "ioption", DbType.String,"insert");
db.AddInParameter(dbCommand, "iattach_id", DbType.Int32, 0);
db.AddInParameter(dbCommand, "iattach_name", DbType.String, iattach_name);
db.AddInParameter(dbCommand, "iattach_extension", DbType.String, iattach_extension);
db.AddInParameter(dbCommand, "iattach_file", DbType.String, iattach_file);
在存储过程中,我使用“Blob”数据类型来保存“iattach\u文件”
需要帮助才能找到解决方案
我的屏幕在这里:
您的iattach\u文件列的类型是什么?它能处理多少数据?请向我们显示存储过程的代码。在代码中,我使用“字符串”数据类型。在存储过程中,我使用“blob”数据类型@MSPOREKI如果您使用的是blob字段,请将其另存为字节数组您应该使用System.byte[]类型作为blob。还有一个不同的数据库类型,检查这里:你检查过这个线程吗?