Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi all

Below is the code i am writing for if radiobutton 1 is clicked the it should enter the value of the textbox else it should enter 0

VB
If RadioButton1.Checked = True Then
                    b.Add(textBox27.Text).ToString()
                Else
                    
                End If

Please tell me what i have to write in the else part
Posted

Without knowing what "b" is, I would say you need this:
VB
If RadioButton1.Checked = True Then
  b.Add(textBox27.Text)
Else
  b.Add("0")
End If
 
Share this answer
 
v2
Comments
ridoy 1-Oct-12 2:14am    
correct..+5
[no name] 1-Oct-12 2:26am    
I am getting this error

Error converting data type nvarchar to int.
JF2015 1-Oct-12 2:29am    
This error probably does not occur in the above code. Show us more of your code so that we can hep you.
[no name] 1-Oct-12 2:32am    
http://www.codeproject.com/Questions/467900/need-help-in-the-error

Please go to this link..i posted this error before
please help me..i m really suffering for this error
[no name] 1-Oct-12 5:15am    
@JF2015: have you checked my problem...please do check and reply...
As you said:

Error converting data type nvarchar to int.


It seems that the "textbox27" do not contains a valid integer so it couldn't be parsed also "Else" block here is fixed to zero, so could you please try something like this:

VB
If RadioButton1.Checked = True Then
    b.Add(Val(textBox27.Text))
Else
    b.Add("0")
End If



Check out VAL functionality here.
 
Share this answer
 
Comments
fjdiewornncalwe 3-Oct-12 13:57pm    
I believe you have it backwards. It is the b.Add("0") that throws the error meaning b is a collection of integers.
Shahan Ayyub 3-Oct-12 14:41pm    
If "b" is an integer collection than what if some one enter "some text here" in textbox27 and this line:

b.Add(textBox27.Text)

will definitely fail to add it to the collection with following error:
"Conversion from string "some text here" to type 'Integer' is not valid."

So my understanding is to have a use of VAL function, IF the end result is going to convert in SQL int datatype, since the error "Error converting data type nvarchar to int." seems to be a sql error.

fjdiewornncalwe 3-Oct-12 15:32pm    
You are correct. My bad.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900