Naše údaje prijímateľa 2% z daní:
Názov: Slovenská aliancia zriedkavých chorôb
Sídlo: Kollárova 11, 902 01 Pezinok
Právna forma: občianske združenie
IČO: 42258073
Užitočné linky k 2% a všetky tlačivá nájdete na www.rozhodni.sk
Imports System.Data.SqlClient Public Async Function GetEmployeesAsync() As Task(Of List(Of Employee)) Dim employees As New List(Of Employee)() Dim connectionString As String = "Server=localhost;Database=YourDatabase;Integrated Security=True;"
Return count End Function Always use parameters when filtering data.
Return employees End Function This approach loads all data into memory and works well for data binding. vb.net code to retrieve data from sql server
Using connection As New SqlConnection(connectionString) Dim query As String = "SELECT EmployeeID, FirstName, LastName, Department, Salary FROM Employees" Dim command As New SqlCommand(query, connection) Try connection.Open() Dim reader As SqlDataReader = command.ExecuteReader() While reader.Read() Dim emp As New Employee() emp.EmployeeID = Convert.ToInt32(reader("EmployeeID")) emp.FirstName = reader("FirstName").ToString() emp.LastName = reader("LastName").ToString() emp.Department = reader("Department").ToString() emp.Salary = Convert.ToDecimal(reader("Salary")) employees.Add(emp) End While reader.Close() Catch ex As SqlException MessageBox.Show("SQL Error: " & ex.Message) End Try End Using
Imports System.Data.SqlClient Public Function GetEmployeesAsDataTable() As DataTable Dim dataTable As New DataTable() Dim connectionString As String = "Server=localhost;Database=YourDatabase;Integrated Security=True;" Imports System
CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY IDENTITY(1,1), FirstName NVARCHAR(50), LastName NVARCHAR(50), Department NVARCHAR(50), Salary DECIMAL(10,2) ); SqlDataReader provides the fastest read performance for large result sets but is read-only and forward-only.
Public Shared Function GetAllEmployees() As List(Of Employee) Dim employees As New List(Of Employee)() Using conn As New SqlConnection(connectionString) Dim sql As String = "SELECT EmployeeID, FirstName, LastName, Department, Salary FROM Employees ORDER BY LastName" Using cmd As New SqlCommand(sql, conn) conn.Open() Using reader As SqlDataReader = cmd.ExecuteReader() While reader.Read() employees.Add(New Employee() With .EmployeeID = reader.GetInt32(0), .FirstName = reader.GetString(1), .LastName = reader.GetString(2), .Department = reader.GetString(3), .Salary = reader.GetDecimal(4) ) End While End Using End Using End Using Return employees End Function End Class .FirstName = reader.GetString(1)
Return employees End Function
Naše údaje prijímateľa 2% z daní:
Názov: Slovenská aliancia zriedkavých chorôb
Sídlo: Kollárova 11, 902 01 Pezinok
Právna forma: občianske združenie
IČO: 42258073
Užitočné linky k 2% a všetky tlačivá nájdete na www.rozhodni.sk