Results 1 to 5 of 5

Thread: Assigning value to a Variable from SqlDataReader

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Posts
    104

    Assigning value to a Variable from SqlDataReader

    How do I assign a value to a variable from the SqlDataReader.Read() method?? In Visual Basic it was done like this:

    VB Code:
    1. while sReader.Read()
    2.      Dim s As String = sReader("fieldnamefromdatabase")
    3. end while

    I have tried converting this statement from VB to C# with no luck. Does anyone know how to perform this action.

    I have tried a couple of other things as well but here is the one I tried first.

    VB Code:
    1. string s;
    2. while (sReader.Read == true)
    3. {
    4. s = sReader["fieldnamefromdatabase"];
    5. }

    Any help is appreciated!!
    Last edited by Polariss; Nov 19th, 2006 at 12:44 PM.

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