Results 1 to 5 of 5

Thread: [RESOLVED] [2005] - SQL 2005 Images

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    111

    Resolved [RESOLVED] [2005] - SQL 2005 Images

    Hey All,

    I currently have some images stored as binary in SQL 2005. I currently have a datagrid which calls an external page to convert the binary into GIF. The datagrid then resizes the images. At the moment, for each image a new row is created.

    What I would like to do is say create a 6 x 6 panel which would display 36 pictures out of the 150 stored. Any suggestions on how I could go about this. I can post my current code if required. I have also tried Response.BinaryWrite but that only displays the 1st Image

  2. #2
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: [2005] - SQL 2005 Images

    You should use a Datalist instead of a datagrid.

    datalist1.RepeatColumns = 6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    111

    Question Re: [2005] - SQL 2005 Images

    Thanks Besoup, worked like a charm . One more question though. I'm trying to implement paging with the datalist using some code I found. When clicking the previous button, I receive the following error message.

    Index -1 is either negative or above rows count.

    Another problem is that there are 3 page indexes in total (0,1,2), but the next button only increments as far as 1. Below is the code I am using.

    VB Code:
    1. <%@ Page Language="vb" %>
    2. <%@ Import Namespace="System.Data" %>
    3. <%@ Import Namespace="System.Data.SqlClient" %>
    4. <%@ Import Namespace="System.Drawing" %>
    5. <%@ Import Namespace="System.Drawing.Imaging" %>
    6. <%@ Import Namespace="System.IO" %>
    7. <%@ Import Namespace="System.Web" %>
    8. <%@ Import Namespace="System.Web.UI" %>
    9. <%@ Import Namespace="System.Web.UI.WebControls" %>
    10. <%@ Import Namespace="System.Web.UI.HTMLControls" %>
    11. <%@ Import Namespace="System.Math" %>
    12.  
    13.  
    14. <script runat="server">
    15.    
    16.     Dim pageddata As New PagedDataSource
    17.    
    18.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    19.         If Not IsPostBack() Then
    20.          
    21.             doPaging()
    22.            
    23.         End If
    24.     End Sub
    25.    
    26.    
    27.     Function BindDataGrid() As DataTable
    28.        
    29.         Dim myConnection As SqlConnection = New SqlConnection("Initial Catalog=EmployeeDB;Data Source=;Integrated Security=True;")
    30.         Const strSQL As String = "SELECT EMPLOYEENO, GIVENNAME, SURNAME, PICTURE FROM STAFF;"
    31.                          
    32.                          
    33.         Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter(strSQL, myConnection)
    34.         Dim dstaccounts As New DataSet()
    35.        
    36.         myConnection.Open()
    37.         myDataAdapter.Fill(dstaccounts, "STAFF")
    38.  
    39.         Return dstaccounts.Tables("STAFF").Copy
    40.  
    41.     End Function
    42.    
    43.     Sub doPaging()
    44.        
    45.         pageddata.DataSource = BindDataGrid().DefaultView
    46.         pageddata.AllowPaging = True
    47.         pageddata.PageSize = 1
    48.  
    49.         Try
    50.             pageddata.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
    51.         Catch ex As Exception
    52.             pageddata.CurrentPageIndex = 0
    53.         End Try
    54.  
    55.         btnPrev.Visible = (Not pageddata.IsFirstPage)
    56.         btnNext.Visible = (Not pageddata.IsLastPage)
    57.  
    58.         pageNumber.Text = "Page " & (pageddata.CurrentPageIndex + 1) & " Of Page " & pageddata.PageCount
    59.  
    60.         datagrid.DataSource = pageddata
    61.         datagrid.DataBind()
    62.        
    63.     End Sub
    64.    
    65.     Public Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
    66.        
    67.         'If pageddata.CurrentPageIndex = 0 Then
    68.            
    69.         'Response.Redirect("e.aspx")
    70.            
    71.         'Else
    72.            
    73.         Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pageddata.CurrentPageIndex - 1))
    74.            
    75.         'End If
    76.     End Sub
    77.  
    78.     Public Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
    79.        
    80.         Response.Redirect(Request.CurrentExecutionFilePath & "?Page=" & (pageddata.CurrentPageIndex + 1))
    81.    
    82.     End Sub
    83.  
    84.  
    85.  
    86.  
    87. Function FormatURL(strArgument) as String
    88.  
    89.                                     Return ("readrealimage.aspx?id=" & strArgument)
    90.  
    91. End Function
    92.  
    93. </script>
    94.  
    95.  
    96.  
    97.  
    98. <html>
    99. <body>
    100.  
    101. <form action="" runat="server">
    102. <asp:DataList id="datagrid" RepeatColumns="6" RepeatDirection="Horizontal" runat="server">
    103.  
    104. <HeaderTemplate>
    105. Employees
    106. </HeaderTemplate>
    107.  
    108. <ItemTemplate>
    109. <asp:Image ID="Image1" runat="server" ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "EMPLOYEENO")) %>'  Visible ='<%# FormatURL(DataBinder.Eval(Container.DataItem, "EMPLOYEENO")) <> "" %>' />
    110. </ItemTemplate>
    111.  
    112.  
    113.  
    114. <FooterTemplate>
    115. Copyright 2008
    116. </FooterTemplate>
    117.  
    118. </asp:DataList>
    119.  
    120. <asp:Button ID="btnPrev" onclick="Prev_Click" text="Previous" runat="server" />
    121. <asp:Button ID="btnNext" onclick="Next_Click" text="Next" runat="server" />
    122.  
    123. <br />
    124.  
    125. <asp:Label ID="pageNumber"  runat="server" />
    126.  
    127. </form>
    128.  
    129. </body>
    130. </html>

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    111

    Talking Re: [2005] - SQL 2005 Images

    Scrap the last post. Another team member amened the code to include the following. Whether it is the best method or not, thats to debate another day.

    VB Code:
    1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         If Not IsPostBack() Then
    3.          
    4.             doPaging()
    5.            
    6.         Else
    7.             Try
    8.                 pageddata.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
    9.             Catch ex As Exception
    10.                 pageddata.CurrentPageIndex = 0
    11.             End Try
    12.         End If
    13.     End Sub

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] [2005] - SQL 2005 Images

    If I were your teammate, I'd change it today

    You shouldn't use try-catch blocks for functionality. You can use Int32.TryParse to see if it is numeric, that saves on the expensive operation of a catch.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width