值类型与列类型不匹配不能存储< System.Byte []>在ProductImage列中。预期的类型是Image。 [英] Type of value has a mismatch with column typeCouldn't store <System.Byte[]> in ProductImage Column. Expected type is Image.

查看:99
本文介绍了值类型与列类型不匹配不能存储< System.Byte []>在ProductImage列中。预期的类型是Image。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,我收到了一个错误。请帮我解决一下:

我正在创建一个购物车项目。当我点击Add to cart Button.Then所有数据保存在一个数据表图像会话。但是当我存储图像时我得到了这个错误:





Hello Friends,I got a error.please help me to resolve it:
I am Creating a shopping cart project.When I click on Add to cart Button.Then all the datails saved in a datatablee image Session.But when i am storing the image I got this Error:


protected void Cartbtn_Click(object sender, EventArgs e)
        {

           
      
                ProductDescriptionObject.SelectedProductSNo = Convert.ToInt16(ProductSNo);

                DataTable dtProducts = ProductDescriptionObject.GetProductsOnTheBaseOfProductId();
                  
              
                DataTable dt = new DataTable(); //storing all of the records

                dt.Columns.Add("ProductSNo", typeof(string)); // adding the columns
                dt.Columns.Add("ProductName", typeof(string));
                dt.Columns.Add("ProductDescription", typeof(string));
                dt.Columns.Add("ProductPrice", typeof(int));
                dt.Columns.Add("ProductImage", typeof(Image));
                dt.Columns.Add("ProductQuantity", typeof(string));
              //  dt.Columns.Add("AvailableStock", typeof(string));

                DataRow dr = dt.NewRow(); //adding the rows
                dr["ProductSNo"] = ProductSNo;
                dr["ProductName"] = Convert.ToString(dtProducts.Rows[0]["ProductName"]);
                dr["ProductDescription"] = Convert.ToString(dtProducts.Rows[0]["ProductDescription"]);
                dr["ProductPrice"] = (dtProducts.Rows[0]["ProductPrice"]);
               dr["ProductImage"] = (dtProducts.Rows[0]["ProductImage"]);
                dr["ProductQuantity"] = ProductQuantity;
              //  dr["AvailableStock"] = lblAvailableStock.Text;

                dt.Rows.Add(dr); //adding the data row in the data table. 

                Session["MyCart"] = dt; //asigning the datatable in the session.
                ItemsCountInCartLinkBtn.Text = dt.Rows.Count.ToString();
            }
           }

推荐答案

DataTable不接受图片数据类型。请参阅: DataColumn.DataType Property [ ^ ]。如果你想使用图像,它应该是 byte [] 数据类型。



我建议阅读本文:检索二进制数据 [ ^ ]和: 在ASP.NET中使用C#将图像转换为byte []和byte []到图像 [ ^ ]





其他资源:

ASP.NET中的图像处理 [ ^ ]

如何在数据表中添加图像? [ ^ ]

用于在DataTable的DataColumn中保存图像的DataType [ ^ ]
DataTable does not accept Image data type. Please see: DataColumn.DataType Property[^]. If you want to work with images, it should be byte[] data type.

I'd suggest to read this: Retrieving Binary Data[^] and this: ow to convert image into byte[] and byte[] to image using C# in ASP.NET[^]


Other resources:
Image Handling In ASP.NET[^]
How can i add image in a datatable?[^]
DataType for Saving Images in DataColumn of DataTable[^]


我发现错误.. 。



DataTable dt = new DataTable(); //存储所有记录



dt.Columns.Add(ProductSNo,typeof(string)); //添加列

dt.Columns.Add(ProductName,typeof(string));

dt.Columns.Add(ProductDescription,typeof(string ));

dt.Columns.Add(ProductPrice,typeof(int));

dt.Columns.Add(ProductImage,typeof(Image)) ; < - 这里我定义了Type Image它应该是Byte [] - >
I find the Error...

DataTable dt = new DataTable(); //storing all of the records

dt.Columns.Add("ProductSNo", typeof(string)); // adding the columns
dt.Columns.Add("ProductName", typeof(string));
dt.Columns.Add("ProductDescription", typeof(string));
dt.Columns.Add("ProductPrice", typeof(int));
dt.Columns.Add("ProductImage", typeof(Image)); <--Here I define Type Image It should be Byte[]-->


这篇关于值类型与列类型不匹配不能存储&lt; System.Byte []&gt;在ProductImage列中。预期的类型是Image。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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