如何使用 datetimepicker 值从数据库中读取数据。我的表单中有一个 datetimepicker 和一个 datagridview。我想使用选定的 datetimepicker 值从 Sql 数据库表中获取数据。我尝试使用此代码
Private Sub BTNFIND_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNFIND.Click
getConnect()
Dim editdate As String
DTPEDITAT.Value= Format(DTPEDITAT.Value, "dd/MM/yyyy")
editdate = DTPEDITAT.Value
MessageBox.Show(editdate)
Try
Conn.Open()
Dim strSQL As String = "SELECT EMP_ID,EMP_NAME,AT_STATUS,AT_REMARK FROM ATTENDANCE WHERE AT_DATE = '" & editdate & "' ORDER BY EMP_NAME ASC"
Dim da As SqlDataAdapter = New SqlDataAdapter(strSQL, Conn)
Dim ds As DataSet = New DataSet
da.Fill(ds, "ATTENDANCE")
Dim dt As DataTable = ds.Tables("ATTENDANCE")
Dim row As DataRow
Dim atstat As String
For Each row In dt.Rows
If row("AT_STATUS") = 1 Then
atstat = "Present"
ElseIf row("AT_STATUS") = 0 Then
atstat = "Absent"
ElseIf row("AT_STATUS") = 0.5 Then
atstat = "Halfday"
Else
atstat = "Error"
End If
For x As Integer = 0 To ATCEDITGRID.Rows.Count - 1
ATCEDITGRID.Rows(x).Cells(2).Value = row("EMP_ID")
ATCEDITGRID.Rows(x).Cells(3).Value = row("EMP_NAME")
ATCEDITGRID.Rows(x).Cells(0).Value = atstat
ATCEDITGRID.Rows(x).Cells(1).Value = row("AT_REMARK")
Next x
Next row
Catch ex As SqlException
MsgBox(ex.Message, MsgBoxStyle.Critical, "SQL Error")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error")
End Try
End Sub
Datagridview 不显示任何内容,也没有错误...