Solved

pass value from Checkbox in a Class

Posted on 2012-12-28
10
357 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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