Results 1 to 14 of 14

Thread: Data Reader

Hybrid View

  1. #1
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Data Reader

    Quote 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;
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  2. #2
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524

    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

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Data Reader

    Quote 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524

    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
  •  



Click Here to Expand Forum to Full Width