
Originally Posted by
Wen Lie
Are you sure ?
coz, I've tried before not to use "Convert" syntax, and returned me an error, which sounds like invalid type when putting the value to a textbox. Even if the content of the field is "string".
That's why I mostly use "convert" when I'm trying to insert a value from field to textbox object.
Well, I'm using C# for ASP.NET. Is it different with the one used for Windows App. ?
Coz I think web and windows in .NET use the same concept, if I'm not wrong. =)
Correct me if I'm wrong.
Thanks n Regards,
WJ
I'm quite sure. You cannot assign anything other than a string to a property of type String so this would be illegal:
Code:
txtFirstName.Text = DR["FirstName"];
because the reader returns the field value as an Object reference. The reference may refer to an object of any type, but if it refers to a string then there's no need or point to converting a string to a string. You should cast the reference as type String instead:
Code:
txtFirstName.Text = (string)DR["FirstName"];
or:
Code:
txtFirstName.Text = DR["FirstName"] as string;