这是我的代码,问题是当数据库中未找到结果时,我应该在哪里以及如何编码以显示未找到记录?
Dim sql = "SELECT Schedule FROM tblTeacherInfo WHERE Schedule = '" & lbl_Date.Text & "'"
lbl_Date.Text = Date.Today
con = connectDB()
con.Open()
mycommand = New SqlCommand(sql, con)
Dim dr As SqlDataReader = mycommand.ExecuteReader
If dr.Read Then
Dim mydate As DateTime = mydate.ToString("MM/dd/yyyy HH:mm:ss")
If txtReceived.TextLength < 8 Then
lbl_Full.Text = "No Record Found"
con.Close()
Else
con.Close()
con.Open()
MsgBox("Data Saved!", MsgBoxStyle.Information, "String Size Specification")
mycommand = New SqlCommand("update tblTeacherInfo set Schedule = '" & lbl_Date.Text & "' where PatronID = @patronid", con)
mycommand.Parameters.AddWithValue("@patronid", txtReceived.Text)
mycommand.ExecuteNonQuery()
con.Close()
txtReceived.Clear()
lbl_Department.Text = ""
lbl_Full.Text = " "
End If
这是一个抽头卡系统。如果我点击卡而不是数据库中的卡,它将使用文本框提示用户该记录尚不存在。我应该在哪里编码?谢谢。编辑:我已经尝试使用IsDBNull,dt.Rows.Count =0。但它也不起作用。也许我只是不知道在哪里以及如何将它们放在这里:D,所以我需要您的建议,非常感谢