string to integer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I had the following error: Input string was not in a correct format.
from the following code
birthday1 is an integer
yrtype is from the dropdownbo
montype ,, ,, ,
daytype ,, ,, ,

Please advise how I get it right. I really get annoyed in c# because we don't need to handle this in vb.ne
Please help

Ra


string x = string.Concat(yrtype.SelectedItem.Text.Trim(),montype.SelectedItem.Text.Trim(),daytype.SelectedItem.Text.Trim());
acmd.Parameters.Add(new SqlParameter("@birthday1", SqlDbType.Int))
acmd.Parameters["@birthday1"].Value = Convert.ToInt32(x);
 
Do you use Option Strict?

However, I don't understand your code, where is the assignment?
Ray Cheung said:
Hi,

I had the following error: Input string was not in a correct format.
from the following code.
birthday1 is an integer
yrtype is from the dropdownbox
montype ,, ,, ,,
daytype ,, ,, ,,

Please advise how I get it right. I really get annoyed in c# because we
don't need to handle this in vb.net
Please help.

Ray



string x = string.Concat(yrtype.SelectedItem.Text.Trim(),montype.SelectedItem.Text.Trim
(),daytype.SelectedItem.Text.Trim());
acmd.Parameters.Add(new SqlParameter("@birthday1", SqlDbType.Int));
acmd.Parameters["@birthday1"].Value = Convert.ToInt32(x);
 
It is okay now
I forgot the montype is notin '01' to '12' forma
the montype is 'Jan' to Dec' instead
Therefore, I need to convert the Jan to 01 prior to adding the yrtype montype and daytype together

Thanks William

Ray
 
Back
Top