ASP.NET
  Home arrow ASP.NET arrow Developing a Data Access Layer for Sybase ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Developing a Data Access Layer for Sybase using ADO.NET: Essentials Continued
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2006-03-27

    Table of Contents:
  • Developing a Data Access Layer for Sybase using ADO.NET: Essentials Continued
  • Binding a dropdown list with information from Sybase database using ADO.NET: explanation
  • Getting a dataset of information from Sybase database using ADO.NET
  • Getting a row of information from Sybase database using ADO.NET

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Developing a Data Access Layer for Sybase using ADO.NET: Essentials Continued


    (Page 1 of 4 )

    This article is the second one in a series focusing on developing a simple DAL (Data Access Layer) for any database using ADO.NET. In this series, we consider Sybase as the database of choice for developing the DAL.
    A downloadable file for this article is available here.

    I enclosed the source code in the form of a single file (“.vb” file).  You can use it right away, as is, or extend it further based on your necessities.  The entire discussion in this article will be based on version .NET 1.1.

    If you are new to configuring Sybase for .NET or new to this series, I strongly suggest you refer to my first article of this series here.

    Binding a dropdown list with information from Sybase database using ADO.NET

    This is the method mainly used to bind pairs of values (key and description) from the database to a dropdown list staying on a web form (or ASP.NET)!  It has a lot of parameters to discuss.  Before starting our discussion of the list of parameters, let us walk through the following complete code first:

    Public Sub BindDropDownList(ByRef dl As DropDownList, ByVal
    sqlSELECT As String, Optional ByVal Caption As String = Nothing,
    Optional ByVal ShowIDandDESCSeparated As Boolean = True, Optional
    ByVal ClearExistingItems As Boolean = True)
            Try
                Dim dt As DataTable = getDataTable(sqlSELECT)
                If dt.Columns.Count < 2 Then
                    Throw New Exception("Atleast 2 cols are required
    to bind, Given SQL Statement: " & sqlSELECT)
                End If
     
                If ClearExistingItems Then dl.Items.Clear()
                If Not Caption Is Nothing Then
                    dl.Items.Add(New ListItem(Caption, Caption))
                    dl.Items.Add(New ListItem("-".PadLeft(150, "-"),
    Caption))
                End If
                Dim dr As DataRow
                If ShowIDandDESCSeparated Then
                    For Each dr In dt.Rows
                        dl.Items.Add(New ListItem(dr(0) & " - " & dr
    (1) & "", dr(0) & ""))
                    Next
                Else
                    For Each dr In dt.Rows
                        dl.Items.Add(New ListItem(dr(1) & "", dr(0) &
    ""))
                    Next
                End If
                dl.SelectedIndex = -1
            Catch ex As Exception
                Throw New Exception(ex.Message & ". Cannot bind
    DropdownList(" & dl.ID & "). Given SQL Statement: " & sqlSELECT)
            End Try
        End Sub



    Let us first discuss the parameter list of the above method.  Following is the list:

    • dl
    • sqlSELECT
    • Caption
    • ShowIDandDESCSeparated
    • ClearExistingItems

    The first one is the dropdown list available in ASP.NET.  You should also observe the “byref” for its declaration.  We need to add items to the dropdown list within our method (which automatically gets affected at the ASP.NET application).  

    The “sqlSELECT” parameter receives the SELECT statement in the form of a string.  We need to have at least two columns selected within the SELECT statement passed to it.  The “Caption” is the first element generally used to display some external message.  The messages would be something like “Select an Item,” “All,” and so on.

    “ShowIDandDESCSeparated” is mainly used to confirm whether it is necessary to display all the IDs along with the description (separated with a hyphen) or not.  The default is true, which means it displays both key and description separated with a hyphen.

    “ClearExistingItems” is mainly used to confirm whether all the items need to be cleared before adding new items or not.  The default is true, which means it clears the existing items before adding new items to the dropdown list.

    I shall explain the above code in next section.

    More ASP.NET Articles
    More By Jagadish Chaterjee


       · Hello guys. This is another contribution for the same series on developing a DAL...
     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT