Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me with this;

I have a dropdown that contains a list of school(the list comes from the database) my problem is, the code doesn't change the value of idS from zero to any other values.

Here's the code:
C#
int.TryParse(drpSchoolOffice.Text, out idS);           
blUser.addUA2(idUser,idS,
                txtLastName.Text.ToUpper(),
               txtFirstName.Text.ToUpper(),
               txtMiddleName.Text.ToUpper(),
             drpUserType.Text,
             txtUsername.Text.ToUpper());

I also tried using this:
C#
int.TryParse(drpSchoolOffice.Text, out idS);
blUser.addUA2(idUser, idS,
                txtLastName.Text.ToUpper(),
               txtFirstName.Text.ToUpper(),
               txtMiddleName.Text.ToUpper(),
             drpUserType.Text,
             txtUsername.Text.ToUpper());
Posted
Updated 29-Aug-13 4:16am
v5
Comments
Anele Ngqandu 29-Aug-13 8:53am    
So you mean every time you click a school you want to insert its ID to a database?
ZurdoDev 29-Aug-13 9:02am    
What's the actual problem?
timJosh 29-Aug-13 10:14am    
My problem is the value for idS is always zero it cannot be overwritten with some other values other than zero.
ZurdoDev 29-Aug-13 10:18am    
Why? What is the value of drpSchoolOffice.Text?
macmacmacmac 29-Aug-13 9:45am    
is your idS table a varchar?

In your question you mentioned "I can't convert the ID of school to a string value to be inserted on the database", but in the code you
are trying to convert to int value from string value hence you are getting "Input string was not in correct format error". To convert int to string use string.TryParse().
 
Share this answer
 
Comments
timJosh 29-Aug-13 9:20am    
Ok I'll try it tnx
I'm not sure what value you are showing in the drpSchoolOffice.Text control but I am guessing you don't really want the droplist's text but you actually want the droplist's selected value. Try this...

C#
int.TryParse(drpSchoolOffice.SelectedValue, out idS);           
blUser.addUA2(idUser,idS,
                txtLastName.Text.ToUpper(),
               txtFirstName.Text.ToUpper(),
               txtMiddleName.Text.ToUpper(),
             drpUserType.Text,
             txtUsername.Text.ToUpper());
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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