System.ArgumentException:参数无效。

编程入门 行业动态 更新时间:2024-10-13 20:20:49
本文介绍了System.ArgumentException:参数无效。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好我在sql server中存储图像。数据类型是Image。 从数据库中检索图像时出现类似System.ArgumentException的错误:参数无效。 此行中的错误img = Image.FromStream(ms)。

Hi am storing images in sql server. The datatype is Image. while retrieving the Images from the database i getting error like System.ArgumentException: Parameter is not valid. The error coming in this line "img = Image.FromStream(ms)".

private void RetriveImage_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(constr); con.Open(); Image img; try { cmd = new SqlCommand("select Pic from emguimg where ID =" + cbxID.SelectedItem.ToString() + "", con); SqlDataReader dr = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(dr); byte[] bytes = (byte[])((byte[])dt.Rows[0]["Pic"]); MemoryStream ms = new MemoryStream(bytes); ms.Write(bytes, 0, bytes.Length); img = Image.FromStream(ms); PicBox.Image = img; PicBox.SizeMode = PictureBoxSizeMode.StretchImage; PicBox.BorderStyle = BorderStyle.Fixed3D; ms.Flush(); ms.Close(); } catch(Exception ex) { WriteLogMessage(ex.ToString()); } }

推荐答案

很可能,它是您存储图像的位置:您的代码容易受到SQL注入的影响,这意味着yoiu总是连接字符串以形成SQL命令。这不仅会让您的用户有机会损坏或破坏您的数据库,还意味着图像存储不起作用。请参阅此处:为什么我会得到一个参数无效。我从数据库中读取图像时出现异常? [ ^ ] Hello Griff感谢您的回复我收到{byte [21]} 是的......这是什么意思? Most likely, it's where you stored the image: your code is vulnerable to SQL Injection which implies that yoiu always concatenate strings to form SQL commands. Not only does that give your users the chance to damage or destroy your database, it also means that image storage doesn't work. See here: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^] "Hello Griff thanks for your reply. I receive the {byte[21]}" Yes...and what does that spell out? [0] 83 S [1] 121 y [2] 115 s [3] 116 t [4] 101 e [5] 109 m [6] 46 . [7] 68 D [8] 114 r [9] 97 a [10] 119 w [11] 105 i [12] 110 n [13] 103 g [14] 46 .

请点击链接,阅读它所说的内容,并注意章节:在我关闭之前......

So follow the link, read what it says, and pay attention to the Section: "Before I close..."

更多推荐

System.ArgumentException:参数无效。

本文发布于:2023-11-12 11:00:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581300.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   System   ArgumentException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!