MS SQL Server
  Home arrow MS SQL Server arrow Page 5 - Completing Your Own SQL Server Based Data ...
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? 
MS SQL SERVER

Completing Your Own SQL Server Based Data Access Helper using COM+ and VB.NET
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2006-08-21

    Table of Contents:
  • Completing Your Own SQL Server Based Data Access Helper using COM+ and VB.NET
  • Customizing the COM class a bit
  • Getting a row of data from the database using a single method
  • Adding a few more helper methods
  • Executing SQL statements along with BLOB values
  • Retrieving a BLOB value from the database

  • 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


    Completing Your Own SQL Server Based Data Access Helper using COM+ and VB.NET - Executing SQL statements along with BLOB values


    (Page 5 of 6 )

    The following method shows how to develop a helper method to work with BLOB values.

        Public Overloads Sub SQLExecute(ByVal strSQL As String, ByRef BLOBColNames() As String, ByRef ByteArrayObjects() As Object)

            Dim Conn As SqlConnection

            Dim cmd As SqlCommand

            Try

                Conn = New SqlConnection(_ConnectionString)

                'validations

                If BLOBColNames Is Nothing Then

                    Throw New Exception("No file column names are provided")

                End If

                If ByteArrayObjects Is Nothing Then

                    Throw New Exception("No ByteArray(ByteArray objects) are provided to upload the files")

                End If

                If BLOBColNames.Length <> ByteArrayObjects.Length Then

                    Throw New Exception("No. of col names doesn't match with no. of Files to be uploaded")

                End If

                cmd = New SqlCommand(strSQL, Conn)

                Dim i As Integer

                Dim ColName As String

                Dim FileByteArray() As Byte

                For i = 0 To BLOBColNames.Length - 1

                    If BLOBColNames(i) Is Nothing Or ByteArrayObjects(i) Is Nothing Then

                        Throw New Exception("One of the Column Name or ByteArrayObject contains no information to upload..")

                    End If

                    FileByteArray = ByteArrayObjects(i)

                    ColName = "@" & Trim(BLOBColNames(i))

                    cmd.Parameters.Add(ColName, System.Data.SqlDbType.Image, FileByteArray.Length).Value = FileByteArray

                Next

                With cmd

                    .Connection.Open()

                    .ExecuteNonQuery()

                    .Connection.Close()

                    .Dispose()

                End With

            Catch ex As Exception

                Try

                    If cmd.Connection.State = ConnectionState.Open Then

                        cmd.Connection.Close()

                        cmd.Dispose()

                    End If

                Catch e As Exception

                    'do nothing...if still error persists

                End Try

                Throw New Exception(ex.Message & ". SQL Statement: " & strSQL)

            End Try

        End Sub

    The following is a simple way to execute the above in DAL:

            If Not (m_Customer.arPhoto Is Nothing) Then

                If m_Customer.arPhoto.Length > 0 Then

                    Dim ImageColumns() As String = New String() {"Photo"}

                    Dim ImageData() As Byte = m_Customer.arPhoto

                    Dim ByteArrayObjects() As Object = New Object() {ImageData}

                    db.SQLExecute("update tCustomers set Photo=@Photo where ICNO='" & m_Customer.sICNO & "'", ImageColumns, ByteArrayObjects)

                End If

            End If

    More MS SQL Server Articles
    More By Jagadish Chaterjee


       · hello guys! this is the continuation of my previous article on developing DAL using...
     

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...





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