Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi;

 

 

 

I am having a problem with implementing this script, the problem is this:

 

 

 

I get an error when trying to run the datagridimages.aspx file it gives me an error saying : Cast from type 'Byte()' to type 'String' is not valid.

 

<%@ Page Language="vb" debug="true"%>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SqlClient" %>

<html>

<head>

<title>ListPersons</title>

<script runat=server>

Sub Page_Load(sender As Object, e As EventArgs)

If Not Page.IsPostBack Then

BindGrid()

End If

End Sub

 

Private Sub BindGrid()

' Create Instance of Connection and Command Object

Dim myConnection As SqlConnection = New SqlConnection("Data Source=172.100.13.48;" _

& "Initial Catalog=PromoStore;User Id=sa;Password=devs3rv;" _

& "Connect Timeout=15;Network Library=dbmssocn;")

Dim myCommand As SqlCommand = New SqlCommand("Select * from bags", myConnection)

 

Try

myConnection.Open()

DG_Persons.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

DG_Persons.DataBind()

Catch SQLexc As SqlException

Response.Write("Error occured while Generating Data. Error is " & SQLexc.ToString())

End Try

End Sub

 

Function FormatURL(strArgument) as String

Return ("readrealimage.aspx?id=" & strArgument)

End Function

</script>

</head>

<body style="font: 10pt verdana">

<h3 align=center>Retrieving images from SqlServer and Displaying in the DataGrid.</h3>

<form id="Form1" method="post" runat="server">

<asp:DataGrid

ID="DG_Persons"

AutoGenerateColumns=False

Width="99%"

HeaderStyle-BackColor="#ff0000"

HeaderStyle-Font-Bold="True"

HeaderStyle-Font-Name="Verdana"

HeaderStyle-Font-Size="13px"

HeaderStyle-ForeColor="#ffffff"

ItemStyle-BackColor=Beige

ItemStyle-Font-Name="verdana"

ItemStyle-Font-Size="13px"

BorderColor="#000000"

Runat=server>

<Columns>

<asp:TemplateColumn HeaderText="Name">

<ItemTemplate>

<asp:Label

Runat="server"

Text='<%# DataBinder.Eval(Container.DataItem, "code") %>' />

</ItemTemplate>

</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Email">

<ItemTemplate>

<asp:Label

Runat="server"

Text='<%# DataBinder.Eval(Container.DataItem, "description") %>' />

</ItemTemplate>

</asp:TemplateColumn>

 

<asp:TemplateColumn HeaderText="Sex">

<ItemTemplate>

<asp:Label

Runat="server"

Text='<%# DataBinder.Eval(Container.DataItem, "division") %>' />

</ItemTemplate>

</asp:TemplateColumn>

 

<asp:TemplateColumn HeaderText="Date of Birth">

<ItemTemplate>

<asp:Label

Runat="server"

Text='<%# DataBinder.Eval(Container.DataItem, "unit_price") %>' />

</ItemTemplate>

</asp:TemplateColumn>

 

<asp:TemplateColumn HeaderText="Image">

<ItemTemplate>

<asp:Image

Width="150" Height="125"

ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "picture")) %>'

Runat=server />

 

</ItemTemplate>

</asp:TemplateColumn>

</Columns>

</asp:DataGrid>

</form>

<br><br><br>

<p align=center><font size=2>

Send your comments to <a href="mailto:das@aspalliance.com">das@aspalliance.com</a>

       <a href=../../default.aspx>Back to Article list</a>

<br><br>

<center><a id="LogoLink" href="http://aspalliance.com"><img src="http://aspalliance.com/libraryaspa/logocounter.asp?article_id=877" border="0" /></a></center>

</font></p>

 

 

</body>

</html>

 

 

I will really appreciate your assistance as I have been battling with this for 2 days and it doesn�t seem that difficult to implement???

 

THANKS !!

Edited by reiqwans
Posted

ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "picture")) 

 

Dont think that is the way to do it....

 

I have written this kind of BLOB handler in the past and doen it by creating an ASP.NET program to output the result and used an OutPutStream to create the output:

 

Response.OutputStream.Write(ThisRow.Item("UploadPic"), 0, CInt(ThisRow.Item("UploadSize")))

 

If you did something along these lines, you could then do:

 

ImageUrl='ShowPic.aspx' 

 

The other options is to figure out why its trying to cast a byte to a string :P

 

Hope that helps a bit :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...