Dataviews with Classes

Hey there,

I am have some trouble with using data views. I have been given an assignment to complete. I have to implement data handling via a new class. The class must have the following:

Properties:
Customer Id (Read/ Write)
First Name (Read Only)
Last Name (Read Only)
City (Read Only)
State (Read Only)
Zip Code (Read Only)

Methods:
GetOrders (returns a data view of all orders for current customer id)
GetOrderDetails(returns a data view of the order items for a given order id)

a custom exception class needs to be created and the new exception will be raised if a customer id passed to the class is not in the database. Both data grids need to be data bound to the dataviews return from your class.

My solution so far: Class Code:
-------------------------------

Public Class claCustomerDetails
Private pCustomerId As String
Private ReadOnly pFirstName As String
Private ReadOnly pLastName As String
Private ReadOnly pCity As String
Private ReadOnly pState As String
Private ReadOnly pZipCode As String

Public Sub New(ByVal cFirstName As String)
cFirstName = pFirstName
End Sub

Public Property CustomerId() As String
Get
Return pCustomerId
End Get
Set(ByVal Value As String)
pCustomerId = Value
End Set
End Property

Public ReadOnly Property FirstName() As String
Get
Return pFirstName
End Get
End Property

Public ReadOnly Property LastName() As String
Get
Return pLastName
End Get
End Property

Public ReadOnly Property City() As String
Get
Return pCity
End Get
End Property

Public ReadOnly Property State() As String
Get
Return pState
End Get
End Property

Public ReadOnly Property ZipCode() As String
Get
Return pZipCode
End Get
End Property

Public Sub GetOrders()
Dim dbCommand As OleDb.OleDbCommand
Dim dbConnection As OleDb.OleDbConnection
Dim dbReader As OleDb.OleDbDataReader
Dim sqlString As String
sqlString = " SELECT * FROM CUSTOMERS"
'dbConnection.ConnectionString = "C:Computeach AssignmentsDoughnut ShopDatabaseThe Doughnut Shop"

dbConnection.Open()

dbCommand.ExecuteReader()

Do While dbReader.Read
'Reading the firstName from the database.
'dbReader!FirstName = FirstName
Loop

dbConnection.Close()

End Sub
End Class

Could some one please help me with the the GetOrders method. I am not sure how to access the database in the class without using the controls, and then link the class with the form.

Any help is appreciated...


Thank You David..

Comments

  • Hi mate,

    I will try to explain somethings, but I might have understood the question wrong...Anyway

    First, GetOrder must be function and return DataView
    second, from your code I assume that you are trying to connecto MS Access DB...I have not checked but seems ok...

    What you must do, instead of DataReader, you should use DataAdapter and Dataset

    when you get the data inside of Dataset, you just have to assign the first table of dataset to the DataView, then return the DataView

    Thats all...I assume that you can know enough...If not just look for the key words in any source, you fill find many examples

    Cheers

    : Hey there,
    :
    : I am have some trouble with using data views. I have been given an assignment to complete. I have to implement data handling via a new class. The class must have the following:
    :
    : Properties:
    : Customer Id (Read/ Write)
    : First Name (Read Only)
    : Last Name (Read Only)
    : City (Read Only)
    : State (Read Only)
    : Zip Code (Read Only)
    :
    : Methods:
    : GetOrders (returns a data view of all orders for current customer id)
    : GetOrderDetails(returns a data view of the order items for a given order id)
    :
    : a custom exception class needs to be created and the new exception will be raised if a customer id passed to the class is not in the database. Both data grids need to be data bound to the dataviews return from your class.
    :
    : My solution so far: Class Code:
    : -------------------------------
    :
    : Public Class claCustomerDetails
    : Private pCustomerId As String
    : Private ReadOnly pFirstName As String
    : Private ReadOnly pLastName As String
    : Private ReadOnly pCity As String
    : Private ReadOnly pState As String
    : Private ReadOnly pZipCode As String
    :
    : Public Sub New(ByVal cFirstName As String)
    : cFirstName = pFirstName
    : End Sub
    :
    : Public Property CustomerId() As String
    : Get
    : Return pCustomerId
    : End Get
    : Set(ByVal Value As String)
    : pCustomerId = Value
    : End Set
    : End Property
    :
    : Public ReadOnly Property FirstName() As String
    : Get
    : Return pFirstName
    : End Get
    : End Property
    :
    : Public ReadOnly Property LastName() As String
    : Get
    : Return pLastName
    : End Get
    : End Property
    :
    : Public ReadOnly Property City() As String
    : Get
    : Return pCity
    : End Get
    : End Property
    :
    : Public ReadOnly Property State() As String
    : Get
    : Return pState
    : End Get
    : End Property
    :
    : Public ReadOnly Property ZipCode() As String
    : Get
    : Return pZipCode
    : End Get
    : End Property
    :
    : Public Sub GetOrders()
    : Dim dbCommand As OleDb.OleDbCommand
    : Dim dbConnection As OleDb.OleDbConnection
    : Dim dbReader As OleDb.OleDbDataReader
    : Dim sqlString As String
    : sqlString = " SELECT * FROM CUSTOMERS"
    : 'dbConnection.ConnectionString = "C:Computeach AssignmentsDoughnut ShopDatabaseThe Doughnut Shop"
    :
    : dbConnection.Open()
    :
    : dbCommand.ExecuteReader()
    :
    : Do While dbReader.Read
    : 'Reading the firstName from the database.
    : 'dbReader!FirstName = FirstName
    : Loop
    :
    : dbConnection.Close()
    :
    : End Sub
    : End Class
    :
    : Could some one please help me with the the GetOrders method. I am not sure how to access the database in the class without using the controls, and then link the class with the form.
    :
    : Any help is appreciated...
    :
    :
    : Thank You David..
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion