Avatar of VBdotnet2005
VBdotnet2005
Flag for United States of America asked on

pass value from Checkbox in a Class

I want to put one of my functions in a class.  However, I am not sure on how to pass checkbox value?


public function UpdateData(byval id as interger, byval chkbAmount as ????) as Boolean      
dim TF as boolean = false
Using con As New SqlConnection(WebConfigurationManager.ConnectionStrings("myConnectionString").ToString)
                con.Open()
                Using comnd As New SqlCommand("mysp", con)
                    comnd.CommandType = Data.CommandType.StoredProcedure
                    comnd.Parameters.AddWithValue("@id", id)
                    comnd.Parameters.AddWithValue("@accountnumber", txtaccountnumber)
             
                    If chkbAmount.Checked = True Then                                <<<<< this line
                        comnd.Parameters.AddWithValue("@noupdate", "Y")
                    Else
                        comnd.Parameters.AddWithValue("@noupdate", "")
                    End If
                    comnd.ExecuteNonQuery()
                  tf = true
                 
                End Using
            End Using
return tf
ASP.NETVisual Basic.NETC#

Avatar of undefined
Last Comment
Nasir Razzaq

8/22/2022 - Mon
kaufmed

Why not just set the parameter type to be Boolean, and then pass the chkbAmount.Checked value to the function call?
Nasir Razzaq

Change

public function UpdateData(byval id as interger, byval chkbAmount as ????) as Boolean  

to

public function UpdateData(byval id as interger, byval chkbAmount as Boolean) as Boolean  


Then pass it chkbAmount.Checked
VBdotnet2005

ASKER
Somethinkg like this?

ClassUpdate

public function UpdateData(byval id as interger, byval chkbAmount  Boolean) as Boolean      
dim TF as boolean = false
Using con As New SqlConnection(WebConfigurationManager.ConnectionStrings("myConnectionString").ToString)
                con.Open()
                Using comnd As New SqlCommand("mysp", con)
                    comnd.CommandType = Data.CommandType.StoredProcedure
                    comnd.Parameters.AddWithValue("@id", id)
                    comnd.Parameters.AddWithValue("@accountnumber", txtaccountnumber)
             
                    If chkbAmount  = True Then                                                    comnd.Parameters.AddWithValue("@noupdate", "Y")
                    Else
                        comnd.Parameters.AddWithValue("@noupdate", "")
                    End If
                    comnd.ExecuteNonQuery()
                  tf = true
                 
                End Using
            End Using
return tf


from page


dim Update_test as new ClassUpdate
dim test as boolean = update_test.UpdateData(id, ???) <<< checkbox is on page, how would I know if True or false?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Nasir Razzaq

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
VBdotnet2005

ASKER
It is on a form. Like this?
dim Update_test as new ClassUpdate
dim test as boolean = update_test.UpdateData(id, chkbAmount.checked) ???
Nasir Razzaq

Yes.
VBdotnet2005

ASKER
Not like this?

dim chkb_tmp as boolean = false
if chkbAmount.checked then
   chkb_tmp = true
end
dim Update_test as new ClassUpdate
dim test as boolean = update_test.UpdateData(id, chkb_tmp) ???


dim test as boolean = update_test.UpdateData(id, chkbAmount.checked) <<< I would not know in advace if chkbAmount is checked
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Nasir Razzaq

Have you tried anything yet?

chkbAmount.Checked will tell you whether its checked or not. You don't have to know that.
VBdotnet2005

ASKER
I just did tried it. Sorry, just a bit confused. Thank you very much codeCruiser
Nasir Razzaq

Glad to help :-)
Your help has saved me hundreds of hours of internet surfing.
fblack61