Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String problem

Status
Not open for further replies.

michaelkrauklis

Programmer
Dec 5, 2001
226
0
0
US
I'm having a problem; I'm getting an Invalid Cast exception thrown when I try to add strings. Here's the code:
Code:
string user="SELECT Password FROM InternalUserPwd where UserName = '"+usr+"'";
if(checktype)
{
	user+=" and UserType = " + type.ToString();
	user+=" and RoleID = " + ((int)type).ToString();
Now the second statement, where I have
Code:
<user+=&quot; and RoleID = &quot; + ((int)type).ToString();>
works, but the first += does not. At this particular point even if I simplify the code to just a concatonation of a string it doesn't work unless I have the
Code:
<((int)type).ToString();>
statement (eg. the code
Code:
<user+=&quot;some string&quot;;>
fails). This just doesn't make sense to me. The += isn't the problem either because the code
Code:
<user=user+&quot;some string&quot;;>
fails as well. It might help that type is an enumerated type, hence the casting to int, but if I just do a straight
Code:
<Console.WriteLine(type.ToString());>
it prints out the correct value in string format. Whaaa? MYenigmaSELF:-9
myenigmaself@myenigmaself.gaiden.com
&quot;If debugging is the process of removing bugs, then programming must be the process of putting them in.&quot; --Dykstra
 
What happens when you do this?
Code:
Console.WriteLine(((int)type).ToString());

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top