Home All Groups Group Topic Archive Search About

Clarification of an example

Author
9 Jan 2006 2:01 AM
jonefer
The following example from "MURACH's VB.NET database programming with ADO.NET"

seems to be missing something: particularly a type for ('As Vendor'?? )
Maybe someone can help clarify what I need to make this work.

This example demonstrates how to create a VendorDB class with the following
shared function:
'=============================================
Public Shared Function GetVendor(ByVal VendorID as Integer) as Vendor
Dim Vendor as New Vendor()
Dim drVendor as SqlDataReader
Dim conPayables as SqlConnection = GetPayablesConnection()
Dim ssqlCommand = "Select VendorID, VendorName, VendorAddress1, " _
                     & "VendorAddress2, VendorCity, VendorState,
VendorZipCode " _
                     & "From Vendors Where VendorID = @VendorID"
Dim cmdVendors as New SqlCommand(sSqlCommand, conPayables)
cmdVendors.Parameters.Add("@VendorID", VendorID)
conPayables.Open()
drVendor = cmdVendors.ExecuteReader(CommandBehavior.SingleRow)
if drVendor.Read Then
    Vendor.ID = drVendor("VendorID")
    Vendor.Name = drVendor("VendorName")
    Vendor.Address1 = drVendor("VendorAddress1").ToString
    Vendor.Address2 = drVendor("VendorAddress2").ToString
    Vendor.City = drVendor("VendorCity")
    Vendor.State = drVendor("VendorState")
    Vendor.ZipCode = drVendor("VendorZipCode")
Else
    Vendor = Nothing
End if

conPayables.Close()
Return Vendor

End Function
'======================================

I'm stuck because I can't set the function type to 'As Vendor'
It doesn't know what that is??
Where did they get that type... ?

there's no explanation in the text other than this:

The GetVendor method accepts a Vendor ID as an argument and then retrieves
the vendor with that ID.  To do that, the Select statement that retrieves the
vendor includes a parameter for the VendorID column, and the value that's
assigned to the VendorID argument is assigned to that parameter.  Notice that
this method uses a data reader to retrieve the vendor row.  Then, if a row
with the specified value is found, the values in that row are assigned to the
properties of a Vendor object that's declared at the beginning of this
procedure.  Otherwise, Nothing is assigned to the Vendor object.  In either
case, the method passes the Vendor object back as its return value.

thank you for any help at all.

Author
9 Jan 2006 2:14 AM
john smith
It looks like a Business Object (a class) they've defined somewhere else
- like what is done in most n-tier enterprise solutions. It's not a
native .net object.
Author
9 Jan 2006 7:39 AM
Cor Ligthert [MVP]
Jonefer,

There should be showed something as a class in your book "Vendor".

Something that most of us do mostly with a datatable, however replaces it in
this case.

Cor
Author
14 Jan 2006 5:24 PM
Chak
If the Vendor class is in a project different from the one that has the
VendorDB class, you need to add a reference to the other project .

Chak.


Show quote
"jonefer" <jone***@discussions.microsoft.com> wrote in message
news:B6EA2008-BBD0-4C1D-92E2-B6D9403CBF26@microsoft.com...
> The following example from "MURACH's VB.NET database programming with
> ADO.NET"
>
> seems to be missing something: particularly a type for ('As Vendor'?? )
> Maybe someone can help clarify what I need to make this work.
>
> This example demonstrates how to create a VendorDB class with the
> following
> shared function:
> '=============================================
> Public Shared Function GetVendor(ByVal VendorID as Integer) as Vendor
> Dim Vendor as New Vendor()
> Dim drVendor as SqlDataReader
> Dim conPayables as SqlConnection = GetPayablesConnection()
> Dim ssqlCommand = "Select VendorID, VendorName, VendorAddress1, " _
>                     & "VendorAddress2, VendorCity, VendorState,
> VendorZipCode " _
>                     & "From Vendors Where VendorID = @VendorID"
> Dim cmdVendors as New SqlCommand(sSqlCommand, conPayables)
> cmdVendors.Parameters.Add("@VendorID", VendorID)
> conPayables.Open()
> drVendor = cmdVendors.ExecuteReader(CommandBehavior.SingleRow)
> if drVendor.Read Then
>    Vendor.ID = drVendor("VendorID")
>    Vendor.Name = drVendor("VendorName")
>    Vendor.Address1 = drVendor("VendorAddress1").ToString
>    Vendor.Address2 = drVendor("VendorAddress2").ToString
>    Vendor.City = drVendor("VendorCity")
>    Vendor.State = drVendor("VendorState")
>    Vendor.ZipCode = drVendor("VendorZipCode")
> Else
>    Vendor = Nothing
> End if
>
> conPayables.Close()
> Return Vendor
>
> End Function
> '======================================
>
> I'm stuck because I can't set the function type to 'As Vendor'
> It doesn't know what that is??
> Where did they get that type... ?
>
> there's no explanation in the text other than this:
>
> The GetVendor method accepts a Vendor ID as an argument and then retrieves
> the vendor with that ID.  To do that, the Select statement that retrieves
> the
> vendor includes a parameter for the VendorID column, and the value that's
> assigned to the VendorID argument is assigned to that parameter.  Notice
> that
> this method uses a data reader to retrieve the vendor row.  Then, if a row
> with the specified value is found, the values in that row are assigned to
> the
> properties of a Vendor object that's declared at the beginning of this
> procedure.  Otherwise, Nothing is assigned to the Vendor object.  In
> either
> case, the method passes the Vendor object back as its return value.
>
> thank you for any help at all.
>

AddThis Social Bookmark Button