我使用字节格式上传数据库中的图像,但我发现错误 [英] i am upload the images in database by using Bytes format but i am geting a error

查看:48
本文介绍了我使用字节格式上传数据库中的图像,但我发现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述









i我使用字节格式上传数据库中的图像。当我我通过使用handler.ashx来检索该图像这里我发现错误是



无法加载Give Url





我写的代码是.Cs文件是..



Hi,



i am upload the images in database by using Bytes format .when i am retrive that image by using handler.ashx Here i am geting error is

"Failed to load the Give Url "


I writen code Is in .Cs file is..

Image1.ImageUrl = "Handler.ashx?ProfileId=" + "MC_3967";





在ASPX代码中



In ASPX CODE

<asp:Image ID="Image1" style="width:150px" Runat="server" />





在处理程序代码....



In handler Code....

try
{
    MemoryStream memoryStream = new MemoryStream();
    SqlDataAdapter cmd = new SqlDataAdapter("select ima from ca where  carprofile='" + pid + "'", CON);
    DataSet ds = new DataSet();
    cmd.Fill(ds);
    if (ds.Tables[0].Rows.Count > 0)
    {
        if (ds.Tables[0].Rows[0][0].ToString() != "")
        {
            byte[] file = (byte[])ds.Tables[0].Rows[0][0];
            memoryStream.Write(file, 0, file.Length);
            context.Response.Buffer = true;
            if (file.Length > 0)
            {
                context.Response.ContentType = "image/jpeg";
                context.Response.BinaryWrite(file);
                memoryStream.Dispose();
            }
        }
        else
        {

        }
    }
    else
    {

    }
}
catch (Exception ex)
{ }







但我得到此错误无法加载Give Url



提供解决方案



谢谢




But Iam Geting This Error "Failed to load the Give Url "

Give a solution

Thank you

推荐答案

一些问题和指示:

1.而不是使用if(ds.Tables [0] .Rows [0] [0] .ToString()!=)如果值为null,无论如何都将失败使用以下内容:

Some questions and pointers:
1. Instead of using if (ds.Tables[0].Rows[0][0].ToString() != "") wich will fail anyway if the value is null use the following:
if (ds.Tables[0].Rows[0][0] != DBNull.Value)





2.下一步你想要指出导致崩溃的线路



3. 查看此处 [ ^ ]也许可以帮助你顺便说一句。



4.别写其他声明,他们没用。

5. don'不要使用空的catch语句吞下异常,通常是为了避免应用程序崩溃,但至少应该记录错误并通知用户。



6.从ca中选择ima,其中carprofile =''+ pid +'' - >使用参数化查询!



希望这会有所帮助。



2. Next you would want to indicate what line causes the crash

3. look here[^] perhaps that helps you on the way.

4. don''t write else statements that are emtpy, they''re useless.
5. don''t swallow Exceptions with empty catch statements, often done to avoid an application crash, but the very least you should log the error and inform the user.

6. "select ima from ca where carprofile=''" + pid + "''" --> use parametrized queries !

Hope this helps.


这篇关于我使用字节格式上传数据库中的图像,但我发现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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