Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Functions - write once, use many 1

Status
Not open for further replies.

Dimitrie1

Programmer
Jan 5, 2007
138
CA
I have a function that I want to call from several pages so I want to write it once, call it several times. How do I do this - someone suggested creating a file functions.aspx and then including it but it didn't work
Code:
Private Function HaveSerials(ByVal First As Int64, ByVal Last As Int64, ByVal Type As String, ByVal Category As String, ByVal Owner As Int64) As Boolean
        'This function checks to see if the items requested to transfer are actually in the possession of the 
        'Transfer Vendor. 
        'It counts the number of items returned from the select and the number of items if all were available
        'If they match then the Transfer Vendor has them all.  
        'This means that the user cannot ask for serials 1-10 knowing that 9 is unavailable.  They 
        'must ask for items 1-8, 10-10 in 2 separate transfers.


        Dim connStr As String = ConfigurationManager.ConnectionStrings("buspassconnectionstring").ConnectionString
        Dim conn As New SqlConnection(connStr)
        Dim cmd As New SqlCommand("Select count(*) as num_returned from item where Condition = 'Sellable' and Type = '" & Type & "' and Category ='" & Category & "' and Serial_Number between " & First & " and " & Last & " and Owner = " & Owner, conn)
        Dim rdr As SqlDataReader
        Dim number As Int32

        Try
            conn.Open()
            rdr = cmd.ExecuteReader
            rdr.Read()
            If Not IsDBNull(rdr("num_returned")) Then
                number = rdr("num_returned")
            Else
                number = 0
            End If
            rdr.Close()
            conn.Close()
        Catch
            number = 0
        End Try

        If number = Last - First + 1 Then
            HaveSerials = True
        Else
            HaveSerials = False
        End If

    End Function
 
thanks - then I did an import and all is well
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top