473,396 Members | 1,929 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,396 software developers and data experts.

Assigning a value within a Dataset to a variable

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.
Nov 16 '05 #1
5 7443
Gav
Try:

IsTaxable =
(char)dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"].ToString();
"Johnny" <Jo****@discussions.microsoft.com> wrote in message
news:02**********************************@microsof t.com...
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.

Nov 16 '05 #2
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" wrote:
Try:

IsTaxable =
(char)dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"].ToString();
"Johnny" <Jo****@discussions.microsoft.com> wrote in message
news:02**********************************@microsof t.com...
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.


Nov 16 '05 #3
Jay
Try

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

or

IsTaxable = dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"].ToString()[0];
"Johnny" <Jo****@discussions.microsoft.com> escreveu na mensagem
news:22**********************************@microsof t.com...
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" wrote:
Try:

IsTaxable =
(char)dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"].ToString();
"Johnny" <Jo****@discussions.microsoft.com> wrote in message
news:02**********************************@microsof t.com...
> 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.


Nov 16 '05 #4
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
Nov 16 '05 #5
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" wrote:
Try

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

or

IsTaxable = dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"].ToString()[0];
"Johnny" <Jo****@discussions.microsoft.com> escreveu na mensagem
news:22**********************************@microsof t.com...
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" wrote:
Try:

IsTaxable =
(char)dsTaxData.Tables["ShipTo"].Rows[0]["is_taxable"].ToString();
"Johnny" <Jo****@discussions.microsoft.com> wrote in message
news:02**********************************@microsof t.com...
> 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.


Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Antonio D'Ottavio | last post by:
Good morning, I've a problem with a dropdownlist located inside any row of a datalist, I fill both datalist and dropdownlist at runtime, the problem is with the dropdownlist infact using the event...
6
by: adamrfrench | last post by:
Let it be mentioned that Javascript is not my forte, so the solution to this could very well be a simple one. I am working on an AJAX function where I can pass a URL and the target ID in, and...
8
by: Woody Splawn | last post by:
Lets say I have a winform that is populated with a dataset. The dataset and data table may have several rows in it. Lets say I am looking at the winform and I want to assign a value to a certain...
2
by: Arne | last post by:
Will the dataset below be returned by value or reference? Public Shared Function getDS() As DataSet Dim ds As New DataSet '... do something Return ds End Function
4
by: John | last post by:
Hi, I'm writing a database programme with C# using a dataset. I want to set a DateTime for a particular field of a row to null (nulls are allowed for that column). When I use: ...
25
by: Sourav | last post by:
Suppose I have a code like this, #include <stdio.h> int *p; void foo(int); int main(void){ foo(3); printf("%p %d\n",p,*p);
8
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I have a large class with a lot of member variables. I also have a function in the class that I would like to change ALL Of the member variables. I am trying to assign...
4
by: cwilliams01 | last post by:
Hello I am new to VB.NET, so sorry if this is really obvious. I have written the following code to fill my dataset from a stored procedure requiring 1 paramter input (from a SQL database). The...
7
by: jodleren | last post by:
Hi I have been looking into php.net, but could not find any proper description. There is a way of assigning variables from functions, while at the same time using them in e.g. an if. I have...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.