0
我在獲取數據行值並將其轉換爲整數時遇到問題。該函數將通過數據表方法從數據庫中檢索數據和計數。我成功獲得計數值,並且我想使用該值來計算員工缺勤日。如何將system.data.dataRow值轉換爲整數
Dim table As New DataTable
Dim AttendCommand As New MySqlCommand("SELECT COUNT(EmployeeID) AS AttendDay FROM employee.attendance WHERE [email protected] AND [email protected]", MysqlConn)
MysqlConn.Open()
AttendCommand.Parameters.AddWithValue("@EmployeeID", txtID.Text)
AttendCommand.Parameters.AddWithValue("@month", Cmonth)
Dim adapter = New MySqlDataAdapter(AttendCommand)
adapter.Fill(table)
If table.Rows.Count > 0 Then
test = CInt(table.Rows(0).ToString)
End If
MysqlConn.Close()
'count absence day after retrieve
Dim countTotal As Integer = 0
Dim total As Integer = 22
countTotal = total - test
我從debug得到的結果是countTotal = 0。
你不需要一個DataAdapter和DataTable該查詢。 'rows = Convert.ToInt32(cmd.ExecuteScalar)'會工作。確保有匹配的數據 – Plutonix