Print Page | Close Window

Problem with String in C#

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=13407
Printed Date: 29 March 2026 at 7:01pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Problem with String in C#
Posted By: Misty
Subject: Problem with String in C#
Date Posted: 18 January 2005 at 1:49pm
I am having problems with a string in C#. Please look at the bolded code below. This is the line of code I'm having problems with. I am getting the following error message:
Compiler Error Message: CS0029: Cannot implicitly convert type 'object' to 'string'

Source Error:



Line 94:
Line 95: //Set module level variable for page title display
Line 96: string FullState = dtsArea.Tables[0].Rows[0]["StateName"];

I don't understand why I'm getting this error message now. FullState is supposed to be a string. How do I solve this?



Replies:
Posted By: Mart
Date Posted: 18 January 2005 at 2:05pm
string FullState = dtsArea.Tables[0].Rows[0]["StateName"].ToString();


Posted By: michael
Date Posted: 18 January 2005 at 9:07pm
You may want to use Localization in your dataset/datatable, then you don't have that problem Wink

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Misty
Date Posted: 18 January 2005 at 9:27pm
Originally posted by michael michael wrote:

You may want to use Localization in your dataset/datatable, then you don't have that problem Wink
 
Can you please explain what localization is? I still have a lot to learn about .Net.


Posted By: Mart
Date Posted: 19 January 2005 at 2:55am
Why would you want to use localization for that? The problem is that ds.Tables.Rows returns an object not a string, which needs to be converted with   .ToString()... how can localization do that?


Posted By: michael
Date Posted: 19 January 2005 at 10:25pm
Yeah, how can it do that well it can't and if I had expressed myself better (or right) it may have been better Tongue Now I think what I wanted to say is to explicitly define the datacolumn datatype i.e.
badTable.Columns.Add("LastName", typeof(String));
Sorry for my attempt to confuse you Wink


-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net