Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi guys..need favor..
after clicking checkbox in gridview,
i also save the datetime in textbox once tick the radiobutton which retrieve from computer current time, i have 4 textbox and 4 radiobutton,
all the datetime should save to database,
so now i cannot save or insert the datetime that i retrieve from radiobutton into database.

this part of my coding:
If RadioButton4.Checked = True Then
                    If ExitTimeOut1 = TextBox4.Text Then
                       
                    Else
                        MyComm2.CommandText = "update ExitPassDetails set ExitTimeOut1 = '" & ExitTimeOut1 & "', Remarks = '" & Reason & "' where ExitID = '" & id & "' "

                        sqlconnect2.Open()

                        Dim result2 As Data.SqlClient.SqlDataReader = MyComm2.ExecuteReader(Data.CommandBehavior.CloseConnection)

                        result2.Read()
                        

                        sqlconnect2.Close()
                    End If

Regards
Aleesya
Posted
Updated 8-May-11 20:08pm
v2

1 solution

What are you writing?!!

VB
If RadioButton4.Checked = True Then '...


Formally, not a bug, but do you really understand what are you doing?!
You compare Boolean with True which is always equal to the same Boolean.
This is approximately the same as writing If 2=2. Must be:

VB
If RadioButton4.Checked = True Then '...


How come you compare
VB
If ExitTimeOut1 = TextBox4.Text Then '...

???

Why the next condition depends on Text? It can be anything. You should understand what do you want. Don't even explain it… understand yourself…

Do you use Debugger? You should.

[EDIT]

Now you explained what you compare. Dreadful!!! It won't work.

The condition
VB
If ExitTimeOut1 = TextBox4.Text Then '...

may never be true, or will happen with low probability. In one tick time can be less, another time more. Isn't that obvious?

Therefore, you always need to use ">=".

Convert text to System.DateTime trigger, compare If System.DateTime >= trigger Then '....

—SA
 
Share this answer
 
v2
Comments
Reena Aleesya 9-May-11 2:34am    
hi, actually i'm not compare..just once tick the radiobutton
Protected Sub RadioButton4_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles RadioButton4.CheckedChanged
TextBox3.Text = System.DateTime.Now
End Sub
retrieve the datetime and pass to textbox then save it to database once click the update button...

regards
Aleesya
Sergey Alexandrovich Kryukov 9-May-11 3:25am    
Bad! Please see my update, after [EDIT].
--SA
Reena Aleesya 9-May-11 21:06pm    
hi..i already stuck here..
may u give some idea..how to save exit time(ExitTimeOut1,ExitTimeIn1,ExitTimeOut2,ExitTimeIn2) which control witk checkbox(4 checkbox for one exit time)...
rgds
Aleesya

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