Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
VB.NET
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.
Posted
Updated 21-Mar-16 20:40pm
v2
Comments
ZurdoDev 21-Mar-16 15:05pm    
Please do not make us guess the error.
Richard Deeming 21-Mar-16 16:05pm    
I hope that's not your real sa password that you've just posted to a public forum.

And why is your application connecting as sa anyway? You should be using an account which has only the permissions required for your application, not a god-level user which can be used to destroy your entire network.

you can do it in many ways. but try this one


VB
'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 am sure this would work for you.
 
Share this answer
 
Comments
Member 11598884 22-Mar-16 17:31pm    
This works but the MsgBox can't work on the Client Side. I tried Response.Write("<script type=""text/javascript"">alert(""Done!"");</script") but it gives me an error about not being able to run a modal. How can I show a message to the client and not loose my formatting of my page.
Engr. S.M. Inuwa 23-Mar-16 4:21am    
what is the exact error you experience?
i wonder! how comes it doesn't worK? Because i test it merely after to sent it to you and the message alert works fine on my system

MsgBox("Done!", MsgBoxStyle.Information, "Notification")

try copy the above and put it in the IF CONDITION
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.
 
Share this answer
 
v2
Comments
Serkan Onat 21-Mar-16 16:55pm    
Answering questions require same skills :)
Patrice T 21-Mar-16 16:58pm    
I know :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900