Showing posts with label according. Show all posts
Showing posts with label according. Show all posts

Tuesday, March 20, 2012

Retrieving image from database

Dear Friends,

I have read many solution over the net, but since I am unable to utilize anyone according to my needs I am seeking help from you people.

I have a table imagedata in sql server 2005 having fields name and imageperson. Name is string and imageperson is Image field. I have successfully stored name of the person and his image in database.

I have populated the dataset from codebehind and bind it to the repeater.

By writing <%#DataBinder.Eval(Container.DataItem,"name")%>

I am a able to retrieve the name of the person. But when I pass photodata as

<%#photogen((DataBinder.Eval(Container.DataItem,"imageperson")))%>

where photogen is function in code behind having structure

public void photogen(byte[] dataretrieved)

{

Response.BinaryWrite(datarerieved)

}

But it is giving error at <%#photogen((DataBinder.Eval(Container.DataItem,"imageperson")))%>

The best overloaded method match for '_Default.photogen(byte[])' has some invalid arguments

AND

Cannot convert object to byte[].

Can anyone please provide me working solution with code for aspx page and code behind.

Thanks and regards

Have a look at the sample projects at:

http://www.codeproject.com/aspnet/EasyThumbs.asp

Tuesday, February 21, 2012

retrieve first record of each customer

I have to retrieve first and last record of each customer according to the Date. Each customer has 10 - 15 records in the table and there are 3000 customers.
how can I retrieve this data.

regardsYou should do something like this:

select *
from table_name a
join (select customer_id, max(date) max_date, min(date) min_date
from table_name
group by custormer_id) b on a.customer_id = b.customer_id and
(date = max_date or date = min_date )

Good Luck.|||Unless you need field information from both records on the one line then you could use:

SELECT
customers.customerid
(SELECT Top 1 c1.DetailsID FROM customerdetails c1 ORDER BY c1.CreateDate ASC) DetailsIDFirst,
(SELECT Top 1 c1.DetailsID FROM customerdetails c1 ORDER BY c1.CreateDate DESC) DetailsIDLast
FROM customers

I'm bringing back the DetailsID - but you could recall any field using this.

Hope this helps.

retrieve data from the gridview

i need to retrieve data from a particular field of the gridview according to the selected row to stored it into session ....

what i had done so far as following:

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
DetailsView1.PageIndex = GridView1.SelectedIndex
Session.Add("receiverName", GridView1.??)

End Sub

??? is the part i am not sure what to code... i tried different method by seems to have problem of convertion.

You can access the seleced row of gridview by using the SelectedRows property, see:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridview.selectedrows(d=ide).aspx