473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 31631
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: spiros | last post by:
Hi, suppose you have the class Class1 and the main program: class Class1 { public: Class1(); ~Class1();
4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
24
by: djozy | last post by:
Please, how can I convert selected item from dropdown list to integer? Thank you
14
by: Chris | last post by:
Hi, I try to print out truth-tables for an &&-operation using the following code, unfortunatly I get compiler errors : for ( byte i1=0; i1<=1; i1++) { for ( byte i2=0; i2<=1; i2++) { bool...
3
by: James | last post by:
Has anyone written a utility to convert a C# form to C++.net? i.e. to convert "using System.Data" to "using namespace System::Data" etc
8
by: ppcdev | last post by:
Here's what I try : LPCTSTR tst = (LPCTSTR) (LPCWSTR) Marshal::StringToHGlobalUni(str); c:\MyNetPrj\Prj0001\stunt.cpp(244): error C2440: 'type cast' : cannot convert from 'System::IntPtr' to...
5
by: Andrew Robinson | last post by:
Any easy answer what is wrong here? private List<string> BodyWords = new List<string>(); string word = "Andrew"; the following causes a compilation error:
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
4
by: cowdung7 | last post by:
public bool searchGame(string gameName) { string searchGame = {"Tibia", "Combat Arms", "Need for Speed", "Moto GP", "Risk", "Red Alert", "Monopoly", "Scrabble"}; if ( searchGame ==...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.