无法转换类型为#System ;DBNull'的对象输入' System.Byte []'在.net

时间:2014-07-24 12:14:26

标签: c# asp.net .net

我是.net的新手。尽管我已经阅读了之前记录的同一问题的其他一些答案。我无法在我的代码中找到它。

请有人解释我在哪里做错了。

我的代码:

string id = context.Request.QueryString["id"];
if (id != null)
                {
                    SAConnection Conn = new SAConnection(WebConfigurationManager.ConnectionStrings["P4ConnectionString"].ConnectionString);
                    string query = "select Embedded_Image from dba.Image where Record_No=" + id;
                    SACommand Cmd = new SACommand(query, Conn);

                    Conn.Open();
                    SADataReader dr = Cmd.ExecuteReader();

                    if (dr.Read())
                    {
                        byte[] bytes = (byte[])dr["Embedded_Image"];
                        context.Response.BinaryWrite(bytes);
                    }
                    dr.Close();
                    Cmd.Dispose();
                    Conn.Close();
                }

当它遇到byte[] bytes = (byte[])dr["Embedded_Image"];行时,我收到错误。

提前致谢

0 个答案:

没有答案
相关问题