Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys...
I really need your favor..
i have exitpass system which have 4 checkbox and 4 textbox, when user go out from office, the guard will tick the checkbox,the datetime will be retrieve from computer datetime, but now my problem is i cannot check thru database either the column is have value or not.
In my code, once i click it will save the current time, but is tick again with the same checkbox it will update the datetime, it should prompt up error said that "This staff have been go out!! "..

Below is my peace of code:

VB
If CheckBox1.Checked = True Then
                           If ExitTimeOut1 = "" Then
                               'MsgBox("This record - " & Empno & " already have been " & ExitTimeOut1 & ". Please choose other records.", MsgBoxStyle.Critical)
                               TextBox4.Enabled = False
                               TextBox5.Enabled = False
                               TextBox6.Enabled = False
                               CheckBox2.Enabled = False
                               CheckBox3.Enabled = False
                               CheckBox4.Enabled = False
                               GridViewExcel.Enabled = False
                               Alert("This record - " & Empno & " already have been " & ExitTimeOut1 & ". Please choose other records.")
                               'result = Convert.ToString(ExitTimeOut1)
                           Else
                               MyComm2.CommandText = "update ExitPassDetails set ExitTimeOut1 = '" & ExitTimeOut1 & "' where ExitID = '" & id & "' "
                               sqlconnect2.Open()
                               Dim result2 As Data.SqlClient.SqlDataReader = MyComm2.ExecuteReader(Data.CommandBehavior.CloseConnection)
                               result2.Read()
                               'Dim MyMessage = "This record - " & Empno & " already Out."
                               'ShowMessage(MyMessage, Page)
                               'MsgBox(id & " - " & Empno & " Successfully.")
                               Alert("This record - " & Empno & " already out " & ExitTimeOut1 & ".")
                               'lblMsg.Text = "This record - " & Empno & " already Out."
                               sqlconnect2.Close()
                           End If
                       End If
                       If CheckBox2.Checked = True Then
                           If ExitTimeIn1 = "" Then
                               ' MsgBox("This record - " & Empno & " already have been " & ExitTimeIn1 & ". Please choose other records.", MsgBoxStyle.Critical)
                               TextBox3.Enabled = False
                               TextBox4.Enabled = False
                               TextBox6.Enabled = False
                               CheckBox1.Enabled = False
                               CheckBox3.Enabled = False
                               CheckBox4.Enabled = False
                               GridViewExcel.Enabled = False
                               Alert("This record - " & Empno & " already have been " & ExitTimeIn1 & ". Please choose other records.")
                           Else
                               MyComm2.CommandText = "update ExitPassDetails set ExitTimeIn1 = '" & ExitTimeIn1 & "' where ExitID = '" & id & "' "
                               sqlconnect2.Open()
                               Dim result2 As Data.SqlClient.SqlDataReader = MyComm2.ExecuteReader(Data.CommandBehavior.CloseConnection)
                               result2.Read()
                               'Dim MyMessage = "This record - " & Empno & " Already In."
                               'ShowMessage(MyMessage, Page)
                               ' MsgBox(id & " - " & Empno & " Successfully.")
                               Alert("This record - " & Empno & " already in " & ExitTimeIn1 & ".")
                               sqlconnect2.Close()
                           End If
                       End If
                      
                       End If
Posted

You can make an AJAX call or do a postback, to check a value in the database. Your message should not say "This staff have been go out!! ", if your client speaks English. It should say 'This staff member is not in the office' or similar.
 
Share this answer
 
Comments
Reena Aleesya 13-Jul-11 21:49pm    
Hi,
I modified the code like this...
If ExitTimeIn2 IsNot Nothing Then
...........
..........

But I can't seem to get it working. I already stumped here..
Any help you could provide would be fantastic.

Thanks
Just stumbled across this and after many hours of banging my head against a brick wall..finally solved!!..
Thanks for those help..
 
Share this answer
 
Seems that you should try String.IsNullOrEmpty Method.
 
Share this answer
 
1. What is the data type of ExitTimeOut1, ExitTimeIn1, etc. ? String or DateTime? Use the debugger to find out their values at runtime. It may help you to understand your code and troubleshoot it.

2. Do not use concatenated strings to execute your sql statements, they're prone to SQL injection attacks. Use Stored Procedure or Parameterized Queries instead.
 
Share this answer
 
Comments
Reena Aleesya 14-Jul-11 20:25pm    
Hi Shameel,
Data type for ExitTimeOut1 is datetime.I also changed my sql query "update ExitPassDetails set ExitTimeOut1 = @ExitTimeOut1 where ExitID = @ExitID"
BUT problem still same,when i save the datetime, then is i re-tick again checkbox that i ticked,it will update the datetime,save the current time..
Thanks

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