List Info

Thread: RE: Error displaying images in gridview




RE: Error displaying images in gridview
country flaguser name
United States
2008-04-29 07:51:35
might it have something to do with sql permissions against the table?
Are you executing embedded SQL vs a stored proc? ; I'm thinking that the tables may not have permissions for direct access.
 
Just so I understand the environment, is this the setup?:
Test - Web Server1 and SQL Server 1
Production is different servers (web2, sql2) (your dev environment)
Does the account that the connection string is using ;have the correct permissions?


Are you writing out a surpressed exception to the UI?

Date: Tue, 29 Apr 2008 17:57:44 +0530
From: mishradipakgmail.com
To: aspnet-databasesaspadvice.com
Subject: [aspnet-databases] RE: Error displaying images in gridview

Dear Tim, Rafeeq,
I tried the code but again its not showing Images in Grid View.
I dont know wats the prob with it.
It Shows images on my development machine but not on system.
My payment is stuck bcos of this error.Since on developments machine it works well ....  while on client side it sometimes stops showing the image.Also same data base works well on our system.
 
Need Help.Dont know wat to do..since no error on develpmnt system.
 
Regards


 
On Wed, Apr 23, 2008 at 7:27 PM, Tim Curtin < tjc_tekhotmail.com">tjc_tekhotmail.com> wrote:
1. Maybe you're supressing an exception. write it out to a label control.
2. try setting the response.contenttype before you response.binarywrite the image bits.
Do While (rdimg.Read())
 &nbsp; Response.ClearHeaders()
 &nbsp; Response.ClearContent()
 &nbsp; Response.ContentType = "image/jpg"
  Response.BinaryWrite(rdimg.Item(
"sampimg"))

Loop
 
Incidently,&nbsp; you should add a 'Finally' where you close the connection.  Finally always runs regardless of an exception
 
sub page_load(...)
   ; Me.lblMessage.Text = ""
end sub
 
function theFunction
 
&nbsp;
dim con as new SqlConnection()
Try
&nbsp;   ; con.connectionstring = ConfigurationManager.ConnectionStrings("connectionstring").connectionstring
  ; &nbsp; .......
&nbsp;
Catch ex As Exception
  ; &nbsp; Me.lblMessage.Text = ex.Message  'View an exception
Finally
&nbsp; &nbsp; &nbsp;  If con.State <> ConnectionState.Closed() Then con.Close()
End Try
 

Tim


Date: Wed, 23 Apr 2008 10:36:49 +0530

From: mishradipakgmail.com">mishradipakgmail.com
To: aspnet-databasesaspadvice.com">aspnet-databasesaspadvice.com
Subject: [aspnet-databases] RE: Error displaying images in gridview

Dear Tim
here is the code............ ; for grid view...............SampImg is the name of the column to display image which has been converted to templte column ..........formaturl is the function used to pass the sno which is identity and primary key.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="snoart" DataSourceID="SqlDataSource4" ForeColor="#333333" GridLines="None" AllowPaging="True" AllowSorting="True">;
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="snoart" HeaderText="SNoArt" InsertVisible="False" ReadOnly="True"
SortExpression="snoart" />
<asp:BoundField DataField="sampname" HeaderText="SampName" SortExpression="sampname" />
<asp:BoundField DataField="artdesign" HeaderText="ArtDesign" SortExpression="artdesign" />
<asp:TemplateField HeaderText="SampImg" SortExpression="sampimg">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("sampimg") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Image ID="Image1" width="75" Height="75" runat="server" ImageUrl='<%# formaturl(databinder.Eval(container.dataitem,("snoart"))) %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
 
 
 
 
 
then there is this format url function in code behind page:--
 

Function formaturl(ByVal strarguement) As String
Return ("imgdisp1.aspx?id=" & strarguement)
End Function  
 
this function passes the snoart as string argument to page imgdisp1
coding for which is:---
 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim strimageid As String = Request.QueryString("id")
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("erpfmgConnectionString").ConnectionString)
Dim cmd3 As SqlCommand conn.Open()
cmd3 =
New SqlCommand("select * from catalogmast where snoart=" & strimageid, conn)
'cmd3 = New SqlCommand("select * from photos", conn)
Dim rdimg As SqlDataReader rdimg = cmd3.ExecuteReader

Do While (rdimg.Read()) Response.BinaryWrite(rdimg.Item(
"sampimg"))
Loop conn.Close()

Catch ex As Exception
End Try  
&nbsp;

End Sub
this is the coding i have used the problem is when i make changes and updates the virtual directory with new changes then it stops showing image and after 1-2 days it starts showing image. Also in between it stops showing image for articles which it used to show. Note:---&nbsp; All the articles have image uploaded and saved...so there is no question of Null Values...
below is the code i used to save image ;to database:---
 
If
FileUpload1.HasFile Then
If FileUpload1.PostedFile.ContentType <> "image/pjpeg" And FileUpload1.PostedFile.ContentType <> "image/gif" And FileUpload1.PostedFile.ContentType <> "image/bmp" And FileUpload1.PostedFile.ContentType <> "image/jpeg" Then lblmsg.Text =
"Select Image File Only"
Exit Sub
End If  

Dim reader As IO.BinaryReader = New IO.BinaryReader(FileUpload1.PostedFile.InputStream)
Dim image() As Byte = reader.ReadBytes(FileUpload1.PostedFile.ContentLength)
Dim insertSql As String = "INSERT INTO catalogmast (sampname,sampdesc,sampimg,arttype,artdesign,buyfrm,buydept) VALUES (samp,desc,Photo1,arttype,artdesign,buyfrm,buydept)" cmd2 =
New SqlCommand(insertSql, conn) cmd2.Parameters.Add(
"samp", SqlDbType.NVarChar, 50) cmd2.Parameters(
"samp").Value = Trim(txtname.Text) cmd2.Parameters.Add(
"desc", SqlDbType.NVarChar, 200) cmd2.Parameters(
"desc").Value = Trim(txtdesc.Text)  
cmd2.Parameters.Add(
"Photo1", SqlDbType.Image) cmd2.Parameters(
"Photo1").Value = image cmd2.Parameters.AddWithValue(
"arttype", DropDownList2.SelectedItem.Text) cmd2.Parameters.AddWithValue(
"artdesign", DropDownList4.SelectedItem.Text) cmd2.Parameters.AddWithValue(
"buyfrm", ddbuyer.SelectedItem.Text) cmd2.Parameters.AddWithValue(
"buydept", dddept.SelectedItem.Text) cmd2.ExecuteNonQuery()
 
end if
conn.Close()
lblmsg.Text =
"Sample Data Saved Successfully" the above coding is in transaction with one more query and with try catch.......
Hope i have made problem clear now.....
Waiting for reply.................
Regards
 
Dipak


On Tue, Apr 22, 2008 at 5:41 PM, Tim Curtin < tjc_tekhotmail.com">tjc_tekhotmail.com> wrote:
- can you post the code/html for the grid? ;
- did you check that the field is not null on the server?
- are you using a page/handler to write the bits back to the page-image?
- are you setting the correct mime type for the image output?
- how are you retrieving the image?


&nbsp;

Date: Tue, 22 Apr 2008 12:42:11 +0530

From: mishradipakgmail.com">mishradipakgmail.com
To: aspnet-databasesaspadvice.com">aspnet-databasesaspadvice.com
Subject: [aspnet-databases] RE: Error displaying images in gridview

Tim,
It shows image individually  always... not in grid view....&nbsp; while sometimes it shows image even in grid view.
Regards
Surendra

On Mon, Apr 21, 2008 at 5:41 AM, Tim Curtin < tjc_tekhotmail.com">tjc_tekhotmail.com> wrote:
Well, not knowing your app, the only things that come to mind are that the image field in the database is null or the url from the page that is creating the web image (<img src='fetchImage.aspx?id=123'> ) is perhaps to another domain and getting shut down by security on the server.&nbsp; Other than that, can you post the code that is retrieving the image?


Date: Mon, 21 Apr 2008 00:35:53 +0530

From: mishradipakgmail.com">mishradipakgmail.com
To: aspnet-databasesaspadvice.com">aspnet-databasesaspadvice.com
Subject: [aspnet-databases] RE: Error displaying images in gridview

Also the link  http://msdn2.microsoft.com/en-us/library/aa479350.aspx &nbsp; displays picture from url stored in database not from image itself stored in database.
while the 2nd link shows how to store image to database and read image from database singly..&nbsp; but the problem i am facing is that sometimes its not displayed in gridview wherein i have converted a column to template insert a image box into it and pass serial no as primary key to other page (where i am reading image and displaying it by response.write (bibary thing)&nbsp;whose url i am setting as url for image control.
So may be now my problem is clearer.
Regards
Dipak
Thanks in Advance

On Mon, Apr 21, 2008 at 12:26 AM, dipak mishra < mishradipakgmail.com">mishradipakgmail.com> wrote:
Thanks TIM, Rafeeq , and others for help,
I think i have not made myself clear i am getting the images to be displayed ...  storing or displaying image is anot an issue....&nbsp; but the problem is that at my clients place it sometimes stops showing the images in grid view....&nbsp; while it shows on image box  individually..
Regards
Dipak

On Fri, Apr 18, 2008 at 6:17 PM, Rafeeq . < kpmrafeeqgmail.com">kpmrafeeqgmail.com> wrote:
Yes Tim,

I think he can apply the same concept to display the image.

--
Regards,
&gt;Rafeeq
&gt;Keralam

On Fri, Apr 18, 2008 at 5:46 PM, Tim Curtin < tjc_tekhotmail.com">tjc_tekhotmail.com> wrote:

&gt;  Rafeeq, this is old ADO.  I think Dipak wants ADO.Net.
&gt;
> > Date: Fri, 18 Apr 2008 13:06:43 +0530
> > From: kpmrafeeqgmail.com">kpmrafeeqgmail.com
> > Subject: [aspnet-databases] RE: Error displaying images in gridview
&gt;
> > To: aspnet-databasesaspadvice.com">aspnet-databasesaspadvice.com
> >
> > Hi Dipak,
>; >
> > Try below method.
&gt; >
> > str = "SELECT image FROM album where id =" & ID
> > rs.Open str, conn
> > if rs.eof then 'No records found
> > Response.End
> > else 'Display the contents
&gt; > Response.ContentType = "image/gif"
> > Response.BinaryWrite(rs("image"))
> > end if
> >
> > You can use red highlighted code in the grid, if you are using extended
&gt; > grid.
> >
> > As you are storing it as binary format. you need to reload it in binary,
&gt; > try.. this
> >
> > Happy coding,
&gt; > --
> > With Warm Regards,
&gt; >
> > >Rafeeq
> > >Keralam
> >
> >
> >
> >
> > On Fri, Apr 18, 2008 at 12:51 PM, dipak mishra < mishradipakgmail.com">mishradipakgmail.com>
> > wrote:
>; >
> > > Dear Allen,
>; > > I am storing Image itself in database not the path to it.
> > > How to display that using image field.
>; > > I am not able to do so.
> > > Plz Help
> > >
> > > On 4/18/08, Allen Moon < howlmoonclearwire.net">howlmoonclearwire.net> wrote:
>; > > > Hey there
> > > > In ASP 2.0 there is a ImageField in gridview that you need to use.
> > > >
> > > > -----Original Message-----
> > > > From: dipak mishra [mailto: mishradipakgmail.com">mishradipakgmail.com]
> > > > Sent: Thursday, April 17, 2008 1:15 PM
> > > > To: aspnet-databasesaspadvice.com">aspnet-databasesaspadvice.com
> > > > Cc: aspnet-databasesaspadvice.com">aspnet-databasesaspadvice.com
> > > > Subject: [aspnet-databases] Error displaying images in gridview
&gt; > > >
> > > > Hi All,
> > > > I am facing a problem on which i would like to have suggestions.
> > > > I have an ERP Application in ASP.net 2.0 with sql 2005 as back end.
> I am
> > > > storing images in database then i am displaying it on a page and
> giving
>; > > the
> > > > URL of that page in grid view template field which has a image
> control.
&gt; > > > Same thins i have been doing in application developed in asp 1.0 and
> sql
> > > 7.0
> > > > the images are displayed correctly everywhere.
> > > > But in this application in Grid view the same image have stopped
&gt; being
> > > > displayed. Although if i view them individually on other page they
> are
> > > > displayed correctly.
> > > > The client has genuine sql server.with service pack 2. Same things
>; are
> > > > working fine on my development machine and similar thing is running
&gt; fine
> > > in
> > > > asp 1.0 and sql 7.0.
> > > > It was running fine on this clients system too. All of a sudden this
> is
> > > not
> > > > displaying image in grid view.
> > > > I have reinstalled sql2005 still same problem.
&gt; > > > The images are saved in sql 2005 this i have checked also the images
>; are
> > > > displayed correctly individually which proves images are in fact
> saved
> > > > actually.
> > > > Any help will be graetly appreciated since i am stuck
> > > > Regards
&gt; > > > Dipak
> > > >
> > > >
> > > >
> > > > Need SQL Advice? http://sqladvice.com
> > > > Need RegEx Advice? http://regexadvice.com
> > > > Need XML Advice? http://xmladvice.com
> > > >
> > > >
> > > >
> > > >
> > > > Need SQL Advice? http://sqladvice.com
> > > > Need RegEx Advice? http://regexadvice.com
> > > > Need XML Advice? http://xmladvice.com
> > > >
> > > >
> > > >
> > > >
> > > > Need SQL Advice? http://sqladvice.com
> > > > Need RegEx Advice? http://regexadvice.com
> > > > Need XML Advice? http://xmladvice.com
> > > >
> > > >
> > > >
> > > > Need SQL Advice? http://sqladvice.com
> > > > Need RegEx Advice? http://regexadvice.com
> > > > Need XML Advice? http://xmladvice.com
> > > >
> > > >
> > > >
> > > > Need SQL Advice? http://sqladvice.com
> > > > Need RegEx Advice? http://regexadvice.com
> > > > Need XML Advice? http://xmladvice.com
> > > >
> > >
> > > Need SQL Advice? http://sqladvice.com
> > > Need RegEx Advice? http://regexadvice.com
> > > Need XML Advice? http://xmladvice.com
> > >
> >
> >
> >
> > Need SQL Advice? http://sqladvice.com
> > Need RegEx Advice? http://regexadvice.com
> > Need XML Advice? http://xmladvice.com
>
>; ------------------------------
> Pack up or back up–use SkyDrive to transfer files or keep extra copies. Learn
>; how.<http://www.windowslive.com/skydrive/overview.html?ocid=TXT_TAGLM_WL_Refresh_skydrive_packup_042008>Need SQL Advice?
> http://sqladvice.com
> Need RegEx Advice? http://regexadvice.com
> Need XML Advice? http://xmladvice.com
>



--
With Warm Regards,

>Rafeeq
>Keralam



Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com


Need SQL Advice? http://sqladvice.com Need RegEx Advice? http://regexadvice.com Need XML Advice? http://xmladvice.com


Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com

Need SQL Advice? http://sqladvice.com Need RegEx Advice? http://regexadvice.com Need XML Advice? http://xmladvice.com


Back to work after baby– how do you know when you're ready? Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com

Need SQL Advice? http://sqladvice.com Need RegEx Advice? http://regexadvice.com Need XML Advice? http://xmladvice.com


Express yourself wherever you are. Mobilize! Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com

Need SQL Advice? http://sqladvice.com Need RegEx Advice? http://regexadvice.com Need XML Advice? http://xmladvice.com


In a rush? Get real-time answers with Windows Live Messenger. Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )