469,323 Members | 1,575 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

Convert a string to bool

I have a value from a field (int) in a table like
string strPlayerLoginStatus = dsPlayer2.Tables[0].Rows[0][1].ToString();

I like to convert the strPlayerLoginStatus from string to int to use it in
an if statement

How do I convert the variable?

regards

reidarT
Nov 16 '05 #1
9 31430
"ReidarT" <re****@eivon.no> ha scritto nel messaggio
news:O4**************@TK2MSFTNGP10.phx.gbl...
I have a value from a field (int) in a table like
string strPlayerLoginStatus = dsPlayer2.Tables[0].Rows[0][1].ToString();
Why don't you get it as you want directly?

// if Rows contains an int
int intPlayerLoginStatus = (int)dsPlayer2.Tables[0].Rows[0][1];

// if Rows contains something similar to an int
int intPlayerLoginStatus = Convert.ToInt32(dsPlayer2.Tables[0].Rows[0][1]);
I like to convert the strPlayerLoginStatus from string to int to use it in
an if statement

How do I convert the variable?


Another way?

// if Rows contains a int as string
int intPlayerLoginStatus =
int.Parse(dsPlayer2.Tables[0].Rows[0][1].ToString());

--
Reporting tool: http://www.neodatatype.net
Nov 16 '05 #2
Convert.ToInt32(strPlayerLoginStatus);
Nov 16 '05 #3
Do you want the bool to be true if you have a record and false if you do
not?

If so... Give the method a return typ of bool and return it based on the
result.

public bool GetTheData()
{
if(the table has records...)
{
return true;
}
else
{
return false;
}
}

public void CallingMethod()
{
if(GetTheData)
{
do something...
}
else
{
do something else...
}
}

Hope this helps.
bobc
"ReidarT" <re****@eivon.no> wrote in message
news:O4**************@TK2MSFTNGP10.phx.gbl...
I have a value from a field (int) in a table like
string strPlayerLoginStatus = dsPlayer2.Tables[0].Rows[0][1].ToString();

I like to convert the strPlayerLoginStatus from string to int to use it in
an if statement

How do I convert the variable?

regards

reidarT

Nov 16 '05 #4
"ReidarT" <re****@eivon.no> wrote in message
news:O4**************@TK2MSFTNGP10.phx.gbl...

<snipped>
I like to convert the strPlayerLoginStatus from string to int to use it in
an if statement


You would need to know which int value is ok (say 1) and which is not ok.

if (some_value == 1)
{
// do something
}

Unless we are completely misunderstanding you,
you need to read a textbook on C#. You shouldn't
use this ng to learn the basics of C#, but to help
you solve problems after the learning stage.

If you have a good library in the neighbourhood
photocopy the first 100 pages of C# Design Patterns by James W. Cooper
ISBN 0-201-84453-2 Don't read the rest of the book. Don't buy the book.
It gives you a super brief and well written introduction into the basics of
C#.

Else buy / read
Learning C# O'Reilly ISBN 0-596-00376-5



Nov 16 '05 #5
try
{
int value = int.Parse( strPlayerLoginStatus );
}
catch (System.FormatException ex)
{
// handle exception
}
"ReidarT" <re****@eivon.no> schreef in bericht
news:O4**************@TK2MSFTNGP10.phx.gbl...
I have a value from a field (int) in a table like
string strPlayerLoginStatus = dsPlayer2.Tables[0].Rows[0][1].ToString();

I like to convert the strPlayerLoginStatus from string to int to use it in
an if statement

How do I convert the variable?

regards

reidarT

Nov 16 '05 #6
"Zach" <wa**********@all.here> wrote in message
news:f2***************************@freeler.nl...

Unless we are completely misunderstanding you,
you need to read a textbook on C#. You shouldn't
use this ng to learn the basics of C#, but to help
you solve problems after the learning stage.
I disagree with you, Zach. The ng is open to all, regardless of experience.
If a question is too trivial for you, don't answer it.

To ReidarT
You are welcome here.

If you have a good library in the neighbourhood
photocopy the first 100 pages of C# Design Patterns by James W. Cooper
ISBN 0-201-84453-2 Don't read the rest of the book. Don't buy the book.


I've heard a lot of weird things before, but this is pretty weird. The book
has a few minor errors in the use of C#, specifically in the demonstration
of a single pattern. The rest of the book is above average, and the first
chapters are excellent (as you noted). If he or she doesn't know design
patterns, the OP may benefit from reading this book in its entirety
(although I usually recommend Shalloway's book for folks just learning DP).
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Nov 16 '05 #7
Also, one person's trivial task is another person's challenge.

"Nick Malik [Microsoft]" <ni*******@hotmail.nospam.com> wrote in message
news:i_********************@comcast.com...
"Zach" <wa**********@all.here> wrote in message
news:f2***************************@freeler.nl...

Unless we are completely misunderstanding you,
you need to read a textbook on C#. You shouldn't
use this ng to learn the basics of C#, but to help
you solve problems after the learning stage.


I disagree with you, Zach. The ng is open to all, regardless of
experience. If a question is too trivial for you, don't answer it.

To ReidarT
You are welcome here.

If you have a good library in the neighbourhood
photocopy the first 100 pages of C# Design Patterns by James W. Cooper
ISBN 0-201-84453-2 Don't read the rest of the book. Don't buy the book.


I've heard a lot of weird things before, but this is pretty weird. The
book has a few minor errors in the use of C#, specifically in the
demonstration of a single pattern. The rest of the book is above average,
and the first chapters are excellent (as you noted). If he or she doesn't
know design patterns, the OP may benefit from reading this book in its
entirety (although I usually recommend Shalloway's book for folks just
learning DP).
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--

Nov 16 '05 #8
Thanks, thats good to hear
reidarT
"Nick Malik [Microsoft]" <ni*******@hotmail.nospam.com> skrev i melding
news:i_********************@comcast.com...
"Zach" <wa**********@all.here> wrote in message
news:f2***************************@freeler.nl...

Unless we are completely misunderstanding you,
you need to read a textbook on C#. You shouldn't
use this ng to learn the basics of C#, but to help
you solve problems after the learning stage.


I disagree with you, Zach. The ng is open to all, regardless of
experience. If a question is too trivial for you, don't answer it.

To ReidarT
You are welcome here.

If you have a good library in the neighbourhood
photocopy the first 100 pages of C# Design Patterns by James W. Cooper
ISBN 0-201-84453-2 Don't read the rest of the book. Don't buy the book.


I've heard a lot of weird things before, but this is pretty weird. The
book has a few minor errors in the use of C#, specifically in the
demonstration of a single pattern. The rest of the book is above average,
and the first chapters are excellent (as you noted). If he or she doesn't
know design patterns, the OP may benefit from reading this book in its
entirety (although I usually recommend Shalloway's book for folks just
learning DP).
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--

Nov 16 '05 #9

"Nick Malik [Microsoft]" <ni*******@hotmail.nospam.com> wrote in message
news:i_********************@comcast.com...
"Zach" <wa**********@all.here> wrote in message
news:f2***************************@freeler.nl...
Re Cooper:
If he or she doesn't know design patterns, the OP
may benefit from reading this book in its entirety I've heard a lot of weird things before


Yes, I get the impression that you have!

(1) There are better books around on the subject of design patterns
(2) The subject matter and the examples used are totally unsuited for
an *absolute* starter.

Re using the ng by an *absolute* starter:
First reading an introductory text will get the OP up to
speed faster. To that end I suggested two excellent texts,
one very concise but sufficient for starters, the other
more comprehensive.



Nov 16 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

24 posts views Thread by djozy | last post: by
14 posts views Thread by Chris | last post: by
3 posts views Thread by James | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.