convert a string to an Int

Hey all,

When I try and do this:

int inputId = (int)recallPlayer.Text;

I get this error:

Error 16 Cannot convert type 'string' to 'int'

what I am trying to do is have a text input box that a user puts a number into and then see if there is a match in the db. Any ideas? Thanks

[510 byte] By [Dvlnblk] at [2007-12-28]
# 1

You can't cast the int explicitly because it may fail, so there is no explicit cast defined. You can use Int32.TryParse instead for your needs: http://msdn2.microsoft.com/ru-ru/library/f02979c7(VS.80).aspx

Thanks

Mark.

MarkDawson at 2007-9-4 > top of Msdn Tech,Visual C#,Visual C# General...
# 2
I figured it out. Okay, have ONE more question for you all, if I do a query on the db and dont get back any record how can I know that and act on it? Thanks
Dvlnblk at 2007-9-4 > top of Msdn Tech,Visual C#,Visual C# General...
# 3
Mark Dawson wrote:

You can't cast the int explicitly because it may fail, so there is no explicit cast defined. You can use Int32.TryParse instead for your needs: http://msdn2.microsoft.com/ru-ru/library/f02979c7(VS.80).aspx

Thanks

Mark.

Thanks Mark, that is exactly...well almost what I did:

int x = Int16.Parse(idToRecall.Text);

Dvlnblk at 2007-9-4 > top of Msdn Tech,Visual C#,Visual C# General...
# 4

Hi,

create a new post for this question, so that people know you are asking a different question to the one in this title, you will get more answers.

Mark.

MarkDawson at 2007-9-4 > top of Msdn Tech,Visual C#,Visual C# General...
# 5
Good idea, and thanks again.
Dvlnblk at 2007-9-4 > top of Msdn Tech,Visual C#,Visual C# General...