Dear Sir,
I'm Trying to how retur a value from a range and Values that are not in the range still appear in VB.NET.
maybe it can be applied with sql or also with LInq via dapper with MS Access database
Please Guide me
Imports System.Data.OleDb
Imports Dapper
Public Class Form1
Dim SalaryService As New SalaryService()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.DataSource = SalaryService.GetSalary()
End Sub
End Class
Public Class Salary
Public Property Id() As Integer
Public Property FirstName() As String
Public Property LastName() As String
Public Property Salary() As Integer
Public Property TaxRate() As Integer
End Class
Public Class SalaryService
Public Function GetOledbConnectionString() As String
Return "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Range.accdb;Persist Security Info=False;"
End Function
Private ReadOnly _conn As OleDbConnection
Private _connectionString As String = GetOledbConnectionString()
Public Sub New()
_conn = New OleDbConnection(_connectionString)
End Sub
Public Function GetSalary() As IEnumerable(Of Salary)
Dim sql = "SELECT Salary.*, TaxRate.TaxRate FROM Salary, TaxRate WHERE Salary BETWEEN [From] and [To];"
Using _conn = New OleDbConnection(GetOledbConnectionString())
Return _conn.Query(Of Salary)(sql).ToList()
End Using
End Function
End Class
Desired result
Table1
ID | FirstName | LastName | Salary | TaxRate |
1 |
Name1 |
Surname1 |
1500 |
15 |
2 |
Name2 |
Surname2 |
2200 |
20 |
3 |
Name3 |
Surname3 |
3100 |
|
Link sample database Ms access