Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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
 
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 30-Sep-12 20:49pm
Code-Hunt7.1K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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:
 
If RadioButton1.Checked = True Then
    b.Add(Val(textBox27.Text))
Else
    b.Add("0")
End If
 

Check out VAL functionality here.
  Permalink  
Comments
Marcus Kramer at 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 at 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.
 
Marcus Kramer at 3-Oct-12 15:32pm
   
You are correct. My bad.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Without knowing what "b" is, I would say you need this:
If RadioButton1.Checked = True Then
  b.Add(textBox27.Text)
Else
  b.Add("0")
End If
  Permalink  
v2
Comments
ridoy at 1-Oct-12 2:14am
   
correct..+5
snehasish nandy at 1-Oct-12 2:26am
   
I am getting this error
 
Error converting data type nvarchar to int.
JF2015 at 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.
snehasish nandy at 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
snehasish nandy at 1-Oct-12 5:15am
   
@JF2015: have you checked my problem...please do check and reply...

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,478
1 OriginalGriff 6,516
2 Peter Leow 3,587
3 Zoltán Zörgő 3,406
4 Richard MacCutchan 2,397


Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100