【发布时间】:2016-06-19 10:26:45
【问题描述】:
我在获取数据行值并转换为整数时遇到了问题。该函数将通过 datatable 方法从数据库中检索数据和计数。我成功获得计数值,我想使用该值来计算员工缺勤天数。
Dim table As New DataTable
Dim AttendCommand As New MySqlCommand("SELECT COUNT(EmployeeID) AS AttendDay FROM employee.attendance WHERE EmployeeID=@EmployeeID AND month=@month", 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
我从调试中得到的结果是 countTotal=0。
【问题讨论】:
-
该查询不需要 DataAdapter 和 DataTable。
rows = Convert.ToInt32(cmd.ExecuteScalar)会起作用。确保有匹配的数据