开发者

If not Check then Add to Cash

开发者 https://www.devze.com 2023-04-03 12:39 出处:网络
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 ch

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开发者_如何学JAVA. 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


===========

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

精彩评论

暂无评论...
验证码 换一张
取 消