troubleshooting Question

IF Statement not working correctly

Avatar of sammySeltzer
sammySeltzerFlag for United States of America asked on
C#ASP.NETVisual Basic.NET
22 Comments1 Solution215 ViewsLast Modified:
Greetings mates,

This one should be simple, I hope.

If textBox is not empty but the associated checkbox is, then insert into cashval field.

If however, textbox is not empty AND checkbox is checked, insert into the chckval field.

The problem is that Yes, it is inserting into the cashval field if the first condition is True but at the same time, inserting the SAME value into chckval field.

Can you please see what i am doing wrong?

I will be glad to provide more info if needed.

Thanks a bunch.

        For x = 1 To 5 Step 1
            dedval = Gridview1.FindControl("ded" & CStr(x))
            chckval = Gridview1.FindControl("chck" & CStr(x))
            chcknumval = Gridview1.FindControl("chcknum" & CStr(x))
            checkboxval = Gridview1.FindControl("chckBox" & CStr(x))
            onetimeval = Gridview1.FindControl("onetime" & CStr(x))
            multival = Gridview1.FindControl("multi" & CStr(x))
            If chckval.Text <> "" And Not checkboxval.Checked Then
                cashval = DirectCast(Gridview1.FindControl("chck" & CStr(x)), TextBox).Text
            Else
                chckval = Gridview1.FindControl("chck" & CStr(x))
            End If
            If dedval.Text <> "-1" And donatechoice.SelectedItem.Value <> "No" Then
                sql += "INSERT INTO employee_ded_amts (employee_id, charity_code, check_amt, chcknum, one_time, bi_weekly, cash, donate_choice, date_stamp) "
                sql += "VALUES ('" & Replace(employee_idLabel.Text, "'", "''") & "','" & Replace(dedval.SelectedValue, "'", "''") & "','" & Replace(chckval.Text, "'", "''") & "','" & Replace(chcknumval.Text, "'", "''") & "','" & Replace(onetimeval.Text, "'", "''") & "','" & multival.Text & "','" & Replace(cashval, "'", "''") & "','" & Replace(donatechoice.SelectedItem.Value, "'", "''") & "','" & Replace(datestamp, "'", "''") & "');"
            End If
            If donatechoice.SelectedItem.Value = "No" Then
                x = 6
                sql += "INSERT INTO employee_ded_amts (employee_id, charity_code, check_amt, chcknum, one_time, bi_weekly, cash, donate_choice, date_stamp) "
                sql += "VALUES ('" & Replace(employee_idLabel.Text, "'", "''") & "','" & Replace(dedval.SelectedValue, "'", "''") & "','" & Replace(chckval.Text, "'", "''") & "','" & Replace(chcknumval.Text, "'", "''") & "','" & Replace(onetimeval.Text, "'", "''") & "','" & Replace(multival.Text, "'", "''") & "','" & Replace(cashval, "'", "''") & "','" & Replace(donatechoice.SelectedItem.Value, "'", "''") & "','" & Replace(datestamp, "'", "''") & "');"
            End If
        Next
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 22 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 22 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros