Clarification of an example

G

Guest

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.
 
J

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.
 
C

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
 
C

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top