Solarion
Honorary Master
- Joined
- Nov 14, 2012
- Messages
- 21,886
Is there another way to get away from this Case statement? Just don't like it.
Business Layer
Data Layer
Business Layer
Code:
Public Function GetDiscById(ByVal disc As String, ByVal progCode As Integer) As DataTable
Dim script As String = ""
Select Case disc
Case "Ford"
script = Scripts.SqlGetCategoryOne
Case "Opel"
script = Scripts.SqlGetCategoryTwo
Case "BMW"
script = Scripts.SqlGetCategoryThree
End Select
Dim dataTable As New DataTable
Dim db As New Data.DayCategoryAccess
dataTable = db.GetData(progCode, script)
Return dataTable
End Function
Data Layer
Code:
Public Function GetData(ByVal progCode As Integer, ByVal sqlScript As String) As DataTable
Dim dataTable As New DataTable
Using sqlDataAdapter As New SqlDataAdapter
sqlDataAdapter.SelectCommand = New SqlCommand
sqlDataAdapter.SelectCommand.Connection = ConnectionAccess.GetConnection()
sqlDataAdapter.SelectCommand.CommandType = CommandType.Text
sqlDataAdapter.SelectCommand.CommandText = sqlScript
sqlDataAdapter.SelectCommand.Parameters.AddWithValue("@ProgCode", progCode)
sqlDataAdapter.Fill(dataTable)
Return dataTable
End Using
End Function