displaying images in datagrid from sql server

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" %>











ListPersons







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)







' Mark the Command as a SPROC



'myCommand.CommandType = CommandType.StoredProcedure







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

















Retrieving images from SqlServer and Displaying in the DataGrid.























' />























' />























' />























' />























'



Runat=server />












































Send your comments to [email protected]



       Back to Article list









image





















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



THANKS !!


Comments

  • Can you bind a DataReader to the DataSource of the DataGrid? I would Fill a DataSet and Bind to a table in the DataSet. If binding to a datareader is possible, I'd say that's impressively creative, but I've never tried/seen that before. I'd say that's the problem.

    Try turning on the trace for the page. That might help.

    -Ray
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion