Assigning a value within a Dataset to a variable

G

Guest

How do I assign a value in a dataset to a variable. I have the following
code that's giving me an error message:

char IsTaxable;
IsTaxable = dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"];

The is_taxable datatype is string and the error message that I'm receiving
is "Cannot implicitly convert type 'object' to 'char'.

I'm a rookie and not sure how to assign the value of my variable. Any help
would be appreciated as I have 5 result sets that with several columns that I
need to assign to variables in my business objects.
 
G

Gav

Try:

IsTaxable =
(char)dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"].ToString();
 
G

Guest

Gav, I get an error message that states "Cannot convert type string to type
char when I try this. Also, I have other variables with datatypes of
decimal, Guid, etc. that I will need to assign and I believe this would only
work for string type variables.

Gav said:
Try:

IsTaxable =
(char)dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"].ToString();


Johnny said:
How do I assign a value in a dataset to a variable. I have the following
code that's giving me an error message:

char IsTaxable;
IsTaxable = dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"];

The is_taxable datatype is string and the error message that I'm receiving
is "Cannot implicitly convert type 'object' to 'char'.

I'm a rookie and not sure how to assign the value of my variable. Any help
would be appreciated as I have 5 result sets that with several columns that I
need to assign to variables in my business objects.
 
J

Jay

Try

IsTaxable =
Convert.ToChar(dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"]);

or

IsTaxable = dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"].ToString()[0];


Johnny said:
Gav, I get an error message that states "Cannot convert type string to
type
char when I try this. Also, I have other variables with datatypes of
decimal, Guid, etc. that I will need to assign and I believe this would
only
work for string type variables.

Gav said:
Try:

IsTaxable =
(char)dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"].ToString();


Johnny said:
How do I assign a value in a dataset to a variable. I have the
following
code that's giving me an error message:

char IsTaxable;
IsTaxable = dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"];

The is_taxable datatype is string and the error message that I'm
receiving
is "Cannot implicitly convert type 'object' to 'char'.

I'm a rookie and not sure how to assign the value of my variable. Any help
would be appreciated as I have 5 result sets that with several columns that I
need to assign to variables in my business objects.
 
C

Cor Ligthert

Johnny,

What is it what you actual want to do, get the first characther

char IsTaxable =
(char)dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"].ToString()[0];

Never tried, however that I assume can work.

Otherwise when you want the full word it becomes
string IsTaxable =
dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"].ToString();

I hope this helps?

Cor
 
G

Guest

Jay, that did it. I was able to use the Convert expression with both Char,
String, and Decimal. I also need to convert to Guid but I haven't tried that
one yet. If I can't, I can always use the string representation of the guid.
Thanks so much, this has been kicking my tale. I really appreciate you guys
responding and so quickly.

Jay said:
Try

IsTaxable =
Convert.ToChar(dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"]);

or

IsTaxable = dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"].ToString()[0];


Johnny said:
Gav, I get an error message that states "Cannot convert type string to
type
char when I try this. Also, I have other variables with datatypes of
decimal, Guid, etc. that I will need to assign and I believe this would
only
work for string type variables.

Gav said:
Try:

IsTaxable =
(char)dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"].ToString();


How do I assign a value in a dataset to a variable. I have the
following
code that's giving me an error message:

char IsTaxable;
IsTaxable = dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"];

The is_taxable datatype is string and the error message that I'm
receiving
is "Cannot implicitly convert type 'object' to 'char'.

I'm a rookie and not sure how to assign the value of my variable. Any
help
would be appreciated as I have 5 result sets that with several columns
that I
need to assign to variables in my business objects.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top