データベースから複数の値を取得したい

実現したいこと

データベースから複数のデータを取得したい

前提

vb.netでデータベースの従業員情報を表示する機能を作成中です。
データベースへの接続はうまくいきますが取得する部分から
エラーが出てうまくいきません。
ログインなどの一人のユーザのデータを取得する場合うまく取得できました

テーブルデータ
empId int
BranchID int
departmentId int
empNo int
fullName nvarchar(20)
KanaName nvarchar(20)
LoginID nvarchar(50)
Password nvarchar(50)
Enable bit
Email varchar(100)
UserRole char(10)
PWUPDay datetime
BossID int

発生している問題・エラーメッセージ

データベースからデータを取得できない

該当のソースコード

vb.net

12Public Class MST_EmployeeDao 3 4 Dim connectString As String = "Persist Security Info=False;Integrated Security=SSPI;database = SalesManager;server=(local);"5 6 Dim connection As SqlConnection = New SqlConnection(connectString)7 8 Public Sub connectDb()9 connection.Open()10 End Sub11 12 Public Sub closeDb()13 connection.Close()14 End Sub15 16 '有効な全従業員を取得する17 Public Function list() As EmpListResult 18 19 Dim sql As String = "select * from MST_Employee where enable=1"20 21 Using command As New SqlCommand(sql, connection)22 23 'ユーザー基本情報24 Dim listData As List(Of MST_Employee) = New List(Of MST_Employee)25 Dim userData As MST_Employee 26 27 Using reader As SqlDataReader = command.ExecuteReader()28 While reader.Read()29 userData = New MST_Employee()30 userData.EmpId = reader.GetInt32(0)31 userData.BranchId = reader.GetInt32(1)32 userData.DepartmentId = reader.GetInt32(2)33 userData.EmpNo = reader.GetInt32(3)34 userData.fullName = reader.GetString(4)35 userData.kanaName = reader.GetString(5)36 userData.loginId = reader.GetString(6)37 userData.password = reader.GetString(7)38 userData.Enable = reader.GetBoolean(8)39 userData.Email = reader.GetString(9)40 userData.UserRole = reader.GetString(10)41 userData.PWUPDay = reader.GetDateTime(11)42 userData.bossId = reader.GetInt32(12)43 44 listData.Add(userData)45 End While46 47 Dim result As EmpListResult = New EmpListResult()48 result.userData = listData 49 50 Return result 51 52 End Using53 54 End Using55 56 End Function57 58End Class59 60//Entityのクラス 61 62Public Class MST_Employee 63 64 Public EmpId As Integer65 66 Public BranchId As Integer67 68 Public DepartmentId As Integer69 70 Public EmpNo As Integer71 72 Public fullName As String73 74 Public kanaName As String75 76 Public loginId As String77 78 Public password As String79 80 Public Enable As Boolean81 82 Public Email As String83 84 Public UserRole As String85 86 Public PWUPDay As DateTime 87 88 Public bossId As Integer89 90 91End Class92 93

試したこと

where句の値をtrueに設定
シンプルなSQLに変更して動作するか試した

補足情報

visual studio 2022

コメントを投稿

0 コメント