Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6545515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:35:41+00:00 2026-05-25T11:35:41+00:00

I ran the below code that Adnan helped me out with last night (Thanks

  • 0

I ran the below code that Adnan helped me out with last night (Thanks very much Adnan).

Basically, the code checks if the amount being entered is check. If it is check, insert the check value into chckval.

If it is cash insert the cash value into cashval.

So far, it is half working. It inserts the check into the check fieldname and inserts 0 into cash fieldname. This is is working great.

What is not working is inserting cash into cash fieldname if the money is cash.

It inserts the cash into cash fieldname as it should BUT it also inserts the same amount into check fieldname. This is not good.

If it is cash and it is inserted into cash fieldname, I want check value to be 0.

Here is the latest code and thanks again.

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

I think there is some issue with the

IF chckval.Text <> "" And Not checkboxval.Checked Then

statment

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:35:42+00:00Added an answer on May 25, 2026 at 11:35 am

    ===========

    Update

    Try changing this line as follows if cashval is a string type,

     cashval = DirectCast(fvEmp.FindControl("chck" & CStr(x)),TextBox).Text;
    

    Kenny thing I figured out is FindControl returns Control Type which need to be converted into TextBox type if it is a TextBox control and then you can use its Text property to get the string. I edited it above. Try it now.

    In C# it will be done like this.

     string cashval = ((TextBox)(fvEmp.FindControl("whatever control name"))).Text;
    

    ==============

    New UPDATE

    chckval = Gridview1.FindControl("chck" & CStr(x))
    

    Kenny now this third line is causing the problem I believe. Try removing this second line from For loop. But when you remove this second line you also will need to assign some value to your chckval TextBox type variable as it can not be null when it is used in query. May be you can assign new empty TextBox

    Or

    You can also make checkval String like you made cashval variable string this will simplify it.

    But whatever value you assign to checkval assign it in this IF statement.

        If chckval.Text <> "" And Not checkboxval.Checked Then
         cashval = DirectCast(Gridview1.FindControl("chck" & CStr(x)), TextBox).Text
         < SET SOME VALUE FOR chckval here ... which is default value which will be used in SQL server> 
          Else
          chckval = Gridview1.FindControl("chck" & CStr(x))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code below. I randomly ran across that it will work if
The code below ensures that when a user accesses control panel, they are ran
I ran across a very strange line of code in a legacy Perl application.
The below code is from my other questions that I have asked here on
I want to run the Java code below in Matlab. It ran successfully in
I am unable to find out more about this default parameter that I ran
Referencing the code below, I have a list of Error objects that has been
When I ran the ruby code below, pressing ctrl + c would immediately stop
So, I am very confused over a quick test that I just ran. I
There are two problems I ran into last night which I have resolved now,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.