获取异常以在数据库中存储数据 [英] Getting Exception To Storing Data In Data Base

查看:128
本文介绍了获取异常以在数据库中存储数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计

i正在处理面部检测窗口表单应用程序第一个用户注册,然后第二次他会来应用程序将识别他我正在使用(Emgu)图像处理,我从互联网上获取代码它正在工作,但我想在数据库中保存图像,为了识别它将从数据库带来图像我试图保存检测到的对象,如







Hi dudes
i am working on face detection windows form application first user register and then second time he will come the application will recognize him i am using (Emgu) image processing , i got code from internet it is working but i want to save image in database , for recognization it will bring image from database i am trying to save detected object like that



public static void SaveImage(Image<gray,> imsgArray)
{
try {
string query = "INSERT INTO Face_Detection(imageContent) VALUES (@payload)";
SqlCommand command = new SqlCommand(query, sqlConnection);
command.Parameters.AddWithValue("@payload", SqlDbType.Binary);
command.Parameters["@payload"].Value = imsgArray.Data;  (  contain Data like  imsgArray.Data{[byte[100,100,1]]})
command.ExecuteNonQuery();
}
catch (Exception ex) {
throw ex;
}
finally { }
}





和我在下面得到例外可以任何身体帮助请。

注意:在数据库列类型是二进制更清楚请找到附加图像。

没有映射从对象类型System.Byte [,,]到已知的托管提供者本机类型。



and i am getting exception below can any body help please.
Note: In database column type is binary for more clear please find attached image.
No mapping exists from object type System.Byte[,,] to a known managed provider native type.

推荐答案

错误是不言自明的:

The error is self explanatory:
No mapping exists from object type System.Byte[,,] to a known managed provider native type.



你不能只在SQL二进制字段中抛出一个3D数组并期望它能解决它如何处理它:它只是存储数据,它不适用于更高级别的结构,如多维数组。因此,当您尝试时,框架会查看您的imsgArray.Data并且无法自动将其转换为一维字节数组。


You can't just throw a 3D array at an SQL Binary field and expect it to work out what to do with it: it just stores data, it doesn't work with higher level constructs such as multidimensional arrays. So when you try, the framework looks at your imsgArray.Data and can't convert it to a one dimensional array of bytes automatically.

BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, imsgArray.Data);
byte[] data = ms.ToArray();

然后,您可以将数据传递给SQL,并在检索时将其反序列化。

You can then pass the data to SQL, and unserialize it when you retrieve it.


这篇关于获取异常以在数据库中存储数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆