Skip to main content
added 22 characters in body
Source Link
nhgrif
  • 25.4k
  • 3
  • 64
  • 129
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

    Dim patient As New Patient

    For Each item As Patient In patient.getAllPatientsInList()

        list.Add(item)

    Next

End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

    Dim patient As New Patient

    For Each item As Patient In patient.getAllPatientsInList()

        list.Add(item)

    Next

End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

    Dim patient As New Patient

    For Each item As Patient In patient.getAllPatientsInList()

        list.Add(item)

    Next

End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

    Dim patient As New Patient

    For Each item As Patient In patient.getAllPatientsInList()

        list.Add(item)

    Next

End Sub
deleted 14 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Get list from database in 3 layer model vb.net. am i using correct Architecture?

I'm working on some testing project. But for For some reason iI think im doiningI'm doing something wrong with the architecture. I createhave a simple example to show what iI mean.

In this example i'mI'm using windowsWindows form when. When the form is loaded iI use the following event  :

Should iI use  Dim patient As New Patient with an empty constructor like this example or should iI approach this another way.? And are there other suggestions you think would improve the architecture of this example ??

Get list from database in 3 layer model vb.net. am i using correct Architecture?

I'm working on some testing project. But for some reason i think im doining something wrong with the architecture. I create a simple example to show what i mean.

In this example i'm using windows form when the form is loaded i use following event  :

Should i use  Dim patient As New Patient with an empty constructor like this example or should i approach this another way. And are there other suggestions you think would improve the architecture of this example ??

Get list from database in 3 layer model

I'm working on some testing project. For some reason I think I'm doing something wrong with the architecture. I have a simple example to show what I mean.

In this example I'm using Windows form. When the form is loaded I use the following event:

Should I use Dim patient As New Patient with an empty constructor like this example or should I approach this another way? And are there other suggestions you think would improve the architecture of this example?

Source Link
Greg
  • 193
  • 5

Get list from database in 3 layer model vb.net. am i using correct Architecture?

I'm working on some testing project. But for some reason i think im doining something wrong with the architecture. I create a simple example to show what i mean.

Database class

Imports DAO
Imports System.Data.SqlClient

Public Class PatientDB

    Dim connectionString As String = "Data Source=GSABBOZMAINPC;Initial Catalog=TestDB;Integrated Security=True"

    Public Function GetAllPatientFromDB() As List(Of PatientDAO)

        Using connection As New SqlConnection(connectionString)


            Dim list As New List(Of PatientDAO)

            Dim sqlString As String = "select * from patient ;"

            Using Command As New SqlCommand(sqlString, connection)

                connection.Open()

                Using reader As SqlDataReader = Command.ExecuteReader

                    While reader.Read

                        Dim firstName As String = reader("firstnamePT").ToString()

                        Dim Name As String = reader("naamPT").ToString()

                        Dim patient As New PatientDAO(Name, firstName)

                        list.Add(patient)

                    End While
    
                End Using

                Return list

            End Using

        End Using  

    End Function

End Class

PatientDAO

Public Class PatientDAO

    Private _name As String
    Private _lastname As String


    Sub New(naam As String, lastname As String)

        _name = naam
        _lastname = lastname

    End Sub

    Public ReadOnly Property Name As String
        Get
            Return _name
        End Get
    End Property

    Public ReadOnly Property Lastname As String
        Get

            Return _lastname

        End Get
    End Property

End Class

Patient

Imports DAO
Imports database_layer

    Public Class Patient
    
        Property naam As String
    
        Property lastname As String
    
    
        Sub New()
    
        End Sub
    
        Sub New(_naam As String, _lastname As String)
    
            naam = _naam
    
            lastname = _lastname
    
        End Sub
    
        Public Sub New(patientDAO As PatientDAO)
    
            naam = patientDAO.Name
            lastname = patientDAO.Lastname
    
        End Sub
    
        Public Function GetDO() As PatientDAO
    
            Return New PatientDAO(naam, lastname)
    
    
        End Function
    
    
        Public Function getAllPatientsInList() As List(Of Patient)
    
            Dim list As New List(Of Patient)
            Dim database As New PatientDB
    
    
            For Each PatientDAO As PatientDAO In database.GetAllPatientFromDB()
    
                Dim patient As New Patient(PatientDAO)
                list.Add(patient)
            Next
    
            Return list
    
    
        End Function
    
        Public Overrides Function ToString() As String
            Return naam + " " + lastname
        End Function

    End Class

In this example i'm using windows form when the form is loaded i use following event :

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

    Dim patient As New Patient

    For Each item As Patient In patient.getAllPatientsInList()

        list.Add(item)

    Next

End Sub

Should i use Dim patient As New Patient with an empty constructor like this example or should i approach this another way. And are there other suggestions you think would improve the architecture of this example ??