Nvarchar与图像不兼容 [英] Nvarchar is incompatible with image

查看:101
本文介绍了Nvarchar与图像不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ch.PoojaBarcode = System.Text.Encoding.Unicode.GetString(BarcodeImage(clsvaboj.Barcode))

这里条码图像查找但是当我插入表格

然后我得到错误

nvarchar与图像不相容



我尝试过:



nvarchar与image

解决方案

<不兼容blockquote>问题是,您尝试插入数据库IMAGE列的是字符串 - 这是NVARCHAR - 该列需要VARBINARY数据,或 byte 数组。

区别在于字符串 char <组成/ code>值,它们是16位值,不一定允许所有可能的值。另一方面,字节数据是8位,允许这8位中的全部值:0到255(含)0/255
你需要什么要做的是将图像转换为字节数据而不是字符串,我无法确切地告诉你如何做到这一点因为我不知道你的BarcodeImage方法返回什么。

这可能会有所帮助,但是: 为什么我会得到一个参数是无效。我从数据库中读取图像时出现异常? [ ^ ] - 它显示如何将Image转换为字节数组并将其传递给DB。


ch.PoojaBarcode =System.Text.Encoding.Unicode.GetString(BarcodeImage(clsvaboj.Barcode))
here barcode image find but when i insert into table
then i got error
nvarchar is incompatible with image
and in database poojabarcode(columnname)alreay image type.

What I have tried:

nvarchar is incompatible with image

解决方案

The problem is that what you are trying to insert into the database IMAGE column is a string - which is NVARCHAR - and the column requires VARBINARY data, or byte array.
The difference is that a string is made of char values, which are 16 bit values which do not necessarily allow for all the possible values. On the other hand byte data is 8 bit and allows the full range of values in those eight bits: 0 to 255 inclusive.
What you need to do is convert your image to byte data instead of string, and I can't tell you exactly how to do that as I have no idea what your BarcodeImage method returns.
This may help, however: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^] - it shows how to convert an Image to an array of bytes and pass it to a DB.


这篇关于Nvarchar与图像不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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