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