|
-
Jun 1st, 2007, 03:24 AM
#1
Re: Data Reader
 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;
-
Jun 1st, 2007, 09:21 PM
#2
Fanatic Member
Re: Data Reader
Hmm....
okei, thanks.
anyway,... why is data reader can't do the move next, previous, first, last... like I did in previous VB 6 ?
Regards,
WJ
-
Jun 1st, 2007, 09:33 PM
#3
Re: Data Reader
 Originally Posted by Wen Lie
Hmm....
okei, thanks.
anyway,... why is data reader can't do the move next, previous, first, last... like I did in previous VB 6 ?
Regards,
WJ
Why can't a car fly? Because it's not designed that way. A DataReader provides read-only, forward-only access to a result set. If you want to be able to navigate the data at will then you need to load it into a DataTable.
-
Jun 1st, 2007, 09:49 PM
#4
Fanatic Member
Re: Data Reader
=)~
hehehe... Just curious.
thanks man...
Regards,
WJ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|