如何验证是否发布了记录 [英] How do I verify if a record is posted
本文介绍了如何验证是否发布了记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在表单页面上创建一个按钮,当单击它时,它将验证表单是否已填写当天,返回一条消息,说明它已完成或未完成。这是我点击按钮后面的代码:
I am trying to make a button on a forms page that when clicked it will verify if the form has been filled out for that day returning a message saying that it is done or not done. Here is my code behind on the button click:
Protected Sub ButtonCheck_Click(sender As Object, e As EventArgs) Handles ButtonCheck.Click
Dim Conn As New SqlClient.SqlConnection
Conn = New SqlConnection("Data Source=VS15IIS01; Initial Catalog=Maintenance;User ID=sa;Password=Password;")
Conn.Open()
If ("SELECT TEST_DATE FROM GeneratorHealthCheck WHERE CONVERT(date,TEST_DATE) = CONVERT(date,getdate())") Then
MsgBox("Done")
Else
MsgBox("Not Done")
End If
Conn.Close()
End Sub
我尝试过的事情:
我很想尝试以上但是我一直在努力一个错误。
What I have tried:
I chave tried the above but I keep getting an error.
推荐答案
你可以通过多种方式做到这一点。但试试这一个
you can do it in many ways. but try this one
'create a variable
Dim result as string
'try connect to your database connections string as you did earlier
Dim Conn As New SqlClient.SqlConnection
Conn = New SqlConnection("Data Source=VS15IIS01; Initial Catalog=Maintenance;User ID=sa;Password=Password;")
Conn.Open()
'select the record to check if there is data,
Dim str as String = "SELECT TEST_DATE FROM GeneratorHealthCheck WHERE CONVERT(date,TEST_DATE) = CONVERT(date,getdate())"
'execute the command
Dim cmd as new sqlCommand(str, Conn)
'read the data
Dim dr as New SQLDataReader
dr = cmd.executeReader
'now check if the query return a value
if dr.hasRows then
dr.read()
result = dr("TEST_DATE").ToString
End If
'now! check if result has value
If result <> nothing Then
MsgBox("Done")
Else
MsgBox("Not Done")
End If
conn.close()
i我相信这对你有用。
i am sure this would work for you.
提出问题是一项技能 [ ^ ]
奇怪的事情附在这里,这个答案打算成为另一个问题的评论,我没有编辑这个问题。我的声誉甚至说我报告了这个问题。
我不明白。
Asking questions is a skill[^]
Weird things append here, This answer was intend to be a comment for another question and I did not edit the question. My reputation points even say that I reported the question.
I don't understand.
这篇关于如何验证是否发布了记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文