Hi forum, I found the solution and I share it [ VB.NET ]. First we have to buill the HTML solution and is as follows, but before, we have to create the table
(cups) into the db, the columns are: ImageID (hit one have to be Idntity: yes) be cause no matter what info the other colums have, we need it to separate every row, if you dont do this the db will be a mess, then, next column
info, then subinfo and finally img (where the image is stored).
After this example we will how to insert images into the db table, very simple.
Everybody knows about the html theres is no rocket science behind it, and next we have the ashx file, that sustain the images into the array, it is very simple to build, here we have to connect with the SQL db and then pass it to binary.
Handler2.ashx ►
<%@ WebHandler Language="VB" Class="Handler2" %>
Imports System.Web
Imports System.Configuration
Imports System.Data.SqlClient
Public Class Handler2
Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim imageid As String = context.Request.QueryString("ImID")
Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("con").ConnectionString)
connection.Open()
Dim command As New SqlCommand("select img from cups where ImageID=" & imageid, connection)
Dim dr As SqlDataReader = command.ExecuteReader()
dr.Read()
context.Response.BinaryWrite(DirectCast(dr(0), [Byte]()))
connection.Close()
context.Response.[End]()
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
Ok, if we test it, we will have with the asp:image control, something like this, but before, check how to call the image, the number 36 is the ID of the image into the db.
Next we have to build the asmx web service file, in this one we have to display the images into the array, in this example I imported many libraries for other purposes but I know that you will discover what are those you need
Photos.asmx ►
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Data
Imports System.Collections.Generic
Imports System.Linq
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Configuration
Imports System.Collections
Imports System.Web.Script.Services
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://microsoft.com/webservices/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Photos
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetPhotos() As AjaxControlToolkit.Slide()
Dim strSQL As String = "SELECT * FROM cups"
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("con").ConnectionString)
conn.Open()
Dim comm As New SqlCommand(strSQL, conn)
Dim da As New SqlDataAdapter(comm)
Dim tblData As New DataTable()
da.Fill(tblData)
conn.Close()
Dim slides As AjaxControlToolkit.Slide() = New AjaxControlToolkit.Slide(tblData.Rows.Count - 1) {}
Dim i As Integer = 0
For Each row As DataRow In tblData.Rows
slides(i) = New AjaxControlToolkit.Slide("Handler2.ashx?ImID=" & row("ImageID").ToString(), "", "")
i += 1
Next
Return slides
End Function
End Class
We need to taste it, go to your web browser and pas to the next url: localhost/myapp/photos.asmx, here, we will see the page that show us the entrance to the service, click over GetPhotos that is the name that I choose, then pass to the page where the INVOKE button appears, click that button and the service will show us the array, and is something like this:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<ArrayOfSlide xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://microsoft.com/webservices/">
<Slide>
<ImagePath>Handler2.ashx?ImID=36</ImagePath>
<Name/>
<Description/>
</Slide>
<Slide>
<ImagePath>Handler2.ashx?ImID=37</ImagePath>
<Name/>
<Description/>
</Slide>
<Slide>
<ImagePath>Handler2.ashx?ImID=38</ImagePath>
<Name/>
<Description/>
</Slide>
</ArrayOfSlide>
If you can see the code above, you are in the right path, and you are done!!!! Run your app and the control slideshowextender have to do it like a champ.
When you create the slide object with the image url, please assign XXX.ashx?url=X as the image url. With the specific parameter url, it will access the ashx page and retrieve the specific image from database.
Jonsey10
Member
1 Points
17 Posts
Slideshowextender ajax problem with SQL database
Dec 13, 2012 01:34 AM|LINK
Hi forum, I found the solution and I share it [ VB.NET ]. First we have to buill the HTML solution and is as follows, but before, we have to create the table (cups) into the db, the columns are: ImageID (hit one have to be Idntity: yes) be cause no matter what info the other colums have, we need it to separate every row, if you dont do this the db will be a mess, then, next column info, then subinfo and finally img (where the image is stored). After this example we will how to insert images into the db table, very simple.
Default.aspx ►
<asp:ScriptManager id="ScriptManager1" runat="server"></asp:ScriptManager> <asp:Image ID="img1" runat="server" Height="172px" Width="133px" /> <asp:SlideShowExtender ID="slideshowextend1" runat="server" TargetControlID="img1" SlideShowServicePath="Photos.asmx" SlideShowServiceMethod="GetPhotos" AutoPlay="false" NextButtonID="btnNext" PreviousButtonID="btnPrev" ContextKey="123" Loop="true"> </asp:SlideShowExtender> <asp:Button ID="btnPrev" runat="server" Text="◄" BackColor="#465564" Font-Names="Arial" BorderWidth="0px" ForeColor="#FFFFFF" Width="90px" /> <asp:Button ID="btnNext" runat="server" Text="►" BackColor="#465564" Font-Names="Arial" BorderWidth="0px" ForeColor="#FFFFFF" Width="90px" />Everybody knows about the html theres is no rocket science behind it, and next we have the ashx file, that sustain the images into the array, it is very simple to build, here we have to connect with the SQL db and then pass it to binary.
Handler2.ashx ►
<%@ WebHandler Language="VB" Class="Handler2" %> Imports System.Web Imports System.Configuration Imports System.Data.SqlClient Public Class Handler2 Implements IHttpHandler Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim imageid As String = context.Request.QueryString("ImID") Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("con").ConnectionString) connection.Open() Dim command As New SqlCommand("select img from cups where ImageID=" & imageid, connection) Dim dr As SqlDataReader = command.ExecuteReader() dr.Read() context.Response.BinaryWrite(DirectCast(dr(0), [Byte]())) connection.Close() context.Response.[End]() End Sub Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return False End Get End Property End ClassOk, if we test it, we will have with the asp:image control, something like this, but before, check how to call the image, the number 36 is the ID of the image into the db.
Next we have to build the asmx web service file, in this one we have to display the images into the array, in this example I imported many libraries for other purposes but I know that you will discover what are those you need
Photos.asmx ►
Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.Data.SqlClient Imports System.Data.Sql Imports System.Data Imports System.Collections.Generic Imports System.Linq Imports System.IO Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Configuration Imports System.Collections Imports System.Web.Script.Services ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. <System.Web.Script.Services.ScriptService()> _ <WebService(Namespace:="http://microsoft.com/webservices/")> _ <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Public Class Photos Inherits System.Web.Services.WebService <WebMethod()> _ Public Function GetPhotos() As AjaxControlToolkit.Slide() Dim strSQL As String = "SELECT * FROM cups" Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("con").ConnectionString) conn.Open() Dim comm As New SqlCommand(strSQL, conn) Dim da As New SqlDataAdapter(comm) Dim tblData As New DataTable() da.Fill(tblData) conn.Close() Dim slides As AjaxControlToolkit.Slide() = New AjaxControlToolkit.Slide(tblData.Rows.Count - 1) {} Dim i As Integer = 0 For Each row As DataRow In tblData.Rows slides(i) = New AjaxControlToolkit.Slide("Handler2.ashx?ImID=" & row("ImageID").ToString(), "", "") i += 1 Next Return slides End Function End ClassWe need to taste it, go to your web browser and pas to the next url: localhost/myapp/photos.asmx, here, we will see the page that show us the entrance to the service, click over GetPhotos that is the name that I choose, then pass to the page where the INVOKE button appears, click that button and the service will show us the array, and is something like this:
If you can see the code above, you are in the right path, and you are done!!!! Run your app and the control slideshowextender have to do it like a champ.
To insert images into the db, follow the next link: http://forums.asp.net/p/1866371/5241251.aspx/1?p=True&t=634912876674598214
Hope this helps someone newbie.
chetan.sarod...
All-Star
65739 Points
11138 Posts
Re: Slideshowextender ajax problem with SQL database
Dec 13, 2012 02:33 AM|LINK
Hi,
First, please check this link to show the image from database onto an ashx page.http://forums.asp.net/t/1218326.aspx
When you create the slide object with the image url, please assign XXX.ashx?url=X as the image url. With the specific parameter url, it will access the ashx page and retrieve the specific image from database.
http://geekswithblogs.net/Bunch/archive/2010/09/17/using-the-ajax-slideshowextender-with-database-images.aspx
http://forums.asp.net/t/1860190.aspx/1
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
Jonsey10
Member
1 Points
17 Posts
Re: Slideshowextender ajax problem with SQL database
Dec 13, 2012 11:04 PM|LINK
↑
Jonsey10
Member
1 Points
17 Posts
Re: Slideshowextender ajax problem with SQL database
Dec 15, 2012 02:49 AM|LINK
↑
sanjayverma_...
Participant
1426 Points
333 Posts
Re: Slideshowextender ajax problem with SQL database
Dec 15, 2012 03:05 AM|LINK
Hi ,
please check ouver here (your datatype )
cmd.Parameters.Add("img", SqlDbType.Int) cmd.Parameters("img").Value = contextKeyJonsey10
Member
1 Points
17 Posts
Re: Slideshowextender ajax problem with SQL database
Dec 15, 2012 08:19 PM|LINK
↑