我在adapter.Fill(dtFuelpriceinfo)
收到错误:
"没有给出所需参数的值"。
TimeOut是日期/时间字段。 但是,如果我用任何具有字符串数据类型的字段替换它,它就可以工作。
我只是不知道如何检索其价值,因为它是一个日期/时间字段。
Public Shared Function Check8HourTimeOut(ByVal EmpID As String) As String
Dim x As String
Dim dtfuelpriceinfo As New DataTable
If Not DBConnection.State = ConnectionState.Open Then
DBConnection.Open()
Else
End If
Dim adapter As New OleDbDataAdapter("SELECT TimeOut FROM EmployeeAttendance where " & _
"EmployeeID='" & EmpID & "' order by WorkingDate desc", DBConnection)
adapter.Fill(dtfuelpriceinfo)
DBConnection.Close()
x = dtfuelpriceinfo.Rows(0).Item(0)
Return x
End Function
答案 0 :(得分:0)
如果您更改了" DataTable"该怎么办?输入" DataSet",如下:
DIM dtfuelpriceinfo as Dataset
并查看在尝试填充DataSet时是否仍然出现错误。 如果是这样,那么我要仔细检查你的SQL,以确保它实际上是在拉一些记录。
另一个想法:也许EmpID是一个整数?您的SQL假定它是一个字符串。你可能知道。
哦和(以下更改可能没有必要,因为"表(0)和#34;可能是可选的/假设,但以防万一:
x = dtfuelpriceinfo.Tables(0).Rows(0).Item(0)
道歉,如果我离开了!
答案 1 :(得分:0)
试试这个
Public Shared Function Check8HourTimeOut(ByVal EmpID As String) As String
Try
Dim x As String = ""
Dim dtfuelpriceinfo As New DataTable
If Not DBConnection.State = ConnectionState.Open Then
DBConnection.Open()
Dim adapter As New OleDbDataAdapter("SELECT TimeOut FROM EmployeeAttendance where " & _
"EmployeeID='" & EmpID.Replace("'", "''") & "' order by WorkingDate desc", DBConnection)
adapter.Fill(dtfuelpriceinfo)
'Check if has recored
If (dtfuelpriceinfo.Rows.Count > 0) Then
If (Not IsDBNull(dtfuelpriceinfo.Rows(0).Item(0))) Then
x = dtfuelpriceinfo.Rows(0).Item(0).ToString("yyyy-MM-dd HH:mm:ss") 'convert date to string representation
End If
End If
DBConnection.Close()
Else
'Do something
End If
Return x
Catch ex As Exception
Return ""
End Try
End Function