Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用c在mysql数据库中插入图像文件#_C#_Mysql_Asp.net - Fatal编程技术网

C# 使用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); 因此,我再次将字节

我正在使用三层体系结构的C#。我必须使用MySQL存储过程插入图像文件。这里我将图像文件转换为字节数组。但是我不能直接插入字节

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。还有一个不同的数据库类型,检查这里:你检查过这个线程吗?