Solved

pass value from Checkbox in a Class

Posted on 2012-12-28
10
355 Views
Last Modified: 2012-12-31
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
0
Comment
Question by:VBdotnet2005
  • 5
  • 4
10 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38728228
Why not just set the parameter type to be Boolean, and then pass the chkbAmount.Checked value to the function call?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38728230
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
0
 

Author Comment

by:VBdotnet2005
ID: 38728429
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?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38728432
>checkbox is on page, how would I know if True or false?

Check its .Checked property. Is it on page or within some other container control such as grid?
0
 

Author Comment

by:VBdotnet2005
ID: 38728434
It is on a form. Like this?
dim Update_test as new ClassUpdate
dim test as boolean = update_test.UpdateData(id, chkbAmount.checked) ???
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38728444
Yes.
0
 

Author Comment

by:VBdotnet2005
ID: 38728452
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
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38728458
Have you tried anything yet?

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

Author Comment

by:VBdotnet2005
ID: 38728462
I just did tried it. Sorry, just a bit confused. Thank you very much codeCruiser
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38728491
Glad to help :-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question