Solved

pass value from Checkbox in a Class

Posted on 2012-12-28
10
350 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 74

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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now