Applying datareader results to label or text???

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Applying datareader results to label or text???

    Please tell me where I'm going wrong on the marked lines***. The code
    is fine to that point. I've only used this code to populate
    dropdownlists using databind to the control. Here, I just need to get
    the one field associated with a variable or a label control.

    THANKS!

    kathy

    Dim Conn3 As New OleDbConnection()
    Dim Rdr3 As OleDbDataReader
    Dim strSQL3 As String = "SELECT Password FROM tblUsers WHERE
    ([UserName] = @UserName)"
    Dim Cmd3 As New OleDbCommand(strSQL3, Conn3)
    Conn3 = New OleDbConnection(strConn)
    Dim prmUserName As OleDbParameter = New OleDbParameter("@UserName",
    OleDbType.VarChar, 50)
    prmUserName.Value = cboUser.SelectedItem.Value
    Cmd3.Parameters.Add(prmUserName)
    Cmd3.Connection = Conn3
    Conn3.Open()
    Rdr3 = Cmd3.ExecuteReader()
    dbPass.Text = Rdr3("Password") '***what is wrong with this
    line?
    Dim strPass As String = Rdr3("Password") '***or what is wrong with
    this line?
    Rdr3.Close()
    Conn3.Close()
    KathyB Guest

  2. Similar Questions and Discussions

    1. Applying a filter results in loss of antialias
      This is a problem I've been dealing with since I've started using Flex. Antialiassed fonts look nice in Flex, but when you put a filter on them (or...
    2. Comparing a Datagrid items to a datareader results - Help Please
      Hi, I have a datagrid which has 3 coloumns adn about 10 rows. The Coloumns have the following fields one is a (chkPrimary) checkbox field and...
    3. Applying text box attributes to newly pasted in text
      How do I forcefully apply 'text box attributes' to newly pasted in text. The settings are this font, & upper case but I end up with that font &...
    4. Outlining text and applying anti-alias..
      "oooride" webforumsuser@macromedia.com wrote: One trick someone taught me once was to make a copy of the text, and outline the copy in a fairly...
    5. Query results in label or text box on form. Is it possible?
      That gives me the "#Error" on the text box when i run it.
  3. #2

    Default Re: Applying datareader results to label or text???

    You have to call the Read method of the datareader to advance it to the
    first record, before you can grab any values. If you are not at the first
    row yet - you cannot access a column value - since there is no row!

    Read return true or false based on whether or not it was able to advance the
    cursor.

    "KathyB" <KathyBurke40@attbi.com> wrote in message
    news:75e8d381.0307021247.3f49414c@posting.google.c om...
    > Please tell me where I'm going wrong on the marked lines***. The code
    > is fine to that point. I've only used this code to populate
    > dropdownlists using databind to the control. Here, I just need to get
    > the one field associated with a variable or a label control.
    >
    > THANKS!
    >
    > kathy
    >
    > Dim Conn3 As New OleDbConnection()
    > Dim Rdr3 As OleDbDataReader
    > Dim strSQL3 As String = "SELECT Password FROM tblUsers WHERE
    > ([UserName] = @UserName)"
    > Dim Cmd3 As New OleDbCommand(strSQL3, Conn3)
    > Conn3 = New OleDbConnection(strConn)
    > Dim prmUserName As OleDbParameter = New OleDbParameter("@UserName",
    > OleDbType.VarChar, 50)
    > prmUserName.Value = cboUser.SelectedItem.Value
    > Cmd3.Parameters.Add(prmUserName)
    > Cmd3.Connection = Conn3
    > Conn3.Open()
    > Rdr3 = Cmd3.ExecuteReader()
    > dbPass.Text = Rdr3("Password") '***what is wrong with this
    > line?
    > Dim strPass As String = Rdr3("Password") '***or what is wrong with
    > this line?
    > Rdr3.Close()
    > Conn3.Close()

    Marina Guest

  4. #3

    Default Applying datareader results to label or text???

    What kind of problem you having? Besides needing to read
    the reader (see posting by Marina) you cannot use
    the .Text property on a text box that is type 'password'.
    You can use the .Attribute.item("Value")= ... to set it
    though...
    >-----Original Message-----
    >Please tell me where I'm going wrong on the marked
    lines***. The code
    >is fine to that point. I've only used this code to
    populate
    >dropdownlists using databind to the control. Here, I just
    need to get
    >the one field associated with a variable or a label
    control.
    >
    >THANKS!
    >
    >kathy
    >
    >Dim Conn3 As New OleDbConnection()
    >Dim Rdr3 As OleDbDataReader
    >Dim strSQL3 As String = "SELECT Password FROM tblUsers
    WHERE
    >([UserName] = @UserName)"
    >Dim Cmd3 As New OleDbCommand(strSQL3, Conn3)
    >Conn3 = New OleDbConnection(strConn)
    >Dim prmUserName As OleDbParameter = New OleDbParameter
    ("@UserName",
    >OleDbType.VarChar, 50)
    >prmUserName.Value = cboUser.SelectedItem.Value
    >Cmd3.Parameters.Add(prmUserName)
    >Cmd3.Connection = Conn3
    >Conn3.Open()
    >Rdr3 = Cmd3.ExecuteReader()
    >dbPass.Text = Rdr3("Password") '***what is
    wrong with this
    >line?
    >Dim strPass As String = Rdr3("Password") '***or what is
    wrong with
    >this line?
    >Rdr3.Close()
    >Conn3.Close()
    >.
    >
    David Waz... Guest

  5. #4

    Default Re: Applying datareader results to label or text???

    Thanks, Marina,

    Could you please tell me HOW to get to the first row. The only time I've
    used datareader was to populate listboxes, can't figure out how to get
    just the one value.

    Thanks.

    KathyBurke

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Kathy Burke Guest

  6. #5

    Default Re: Applying datareader results to label or text???

    I did tell you how to do this. I said to call the Read method, and I
    explained its return values and what it means.

    For more information, please look up the OleDbDataReader class in the
    documentation.

    "Kathy Burke" <kathyburke40@attbi.com> wrote in message
    news:uyW6ILWQDHA.2636@TK2MSFTNGP10.phx.gbl...
    > Thanks, Marina,
    >
    > Could you please tell me HOW to get to the first row. The only time I've
    > used datareader was to populate listboxes, can't figure out how to get
    > just the one value.
    >
    > Thanks.
    >
    > KathyBurke
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Marina Guest

  7. #6

    Default Re: Applying datareader results to label or text???

    Yep. Marina did give you the right info...

    So to use this in the code you provided earlier, it would look like:

    Dim Conn3 As New OleDbConnection()
    Dim Rdr3 As OleDbDataReader
    Dim strSQL3 As String = "SELECT Password FROM tblUsers WHERE _
    ([UserName] = @UserName)"
    Dim Cmd3 As New OleDbCommand(strSQL3, Conn3)
    Conn3 = New OleDbConnection(strConn)
    Dim prmUserName As OleDbParameter = New OleDbParameter("@UserName",
    OleDbType.VarChar, 50)
    prmUserName.Value = cboUser.SelectedItem.Value
    Cmd3.Parameters.Add(prmUserName)
    Cmd3.Connection = Conn3
    Conn3.Open()
    Rdr3 = Cmd3.ExecuteReader()

    If Rdr3.Read() Then ' <--- positions to the first record
    dbPass.Text = Rdr3("Password") '***what is wrong with this
    line?
    Dim strPass As String = Rdr3("Password") '***or what is wrong with this
    line?
    End If
    Rdr3.Close()
    Conn3.Close()

    This should give you what you want.
    --
    Jim Blizzard
    Sr .NET Developer Evangelist
    Microsoft

    Your Potential. Our Passion.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Please reply to newsgroups only, so that others may benefit. Thanks.


    --------------------
    >From: "Marina" <zlatkinam@nospam.hotmail.com>
    >References: <O8IzCvNQDHA.304@tk2msftngp13.phx.gbl>
    <uyW6ILWQDHA.2636@TK2MSFTNGP10.phx.gbl>
    >Subject: Re: Applying datareader results to label or text???
    >Date: Thu, 3 Jul 2003 09:30:44 -0400
    >Lines: 22
    >X-Priority: 3
    >X-MSMail-Priority: Normal
    >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    >Message-ID: <eBEbPdWQDHA.2832@TK2MSFTNGP10.phx.gbl>
    >Newsgroups: microsoft.public.dotnet.framework.aspnet
    >NNTP-Posting-Host: 63.72.155.97
    >Path:
    cpmsftngxa09.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA05.phx.gbl!TK2MSFTNGP08
    ..phx.gbl!TK2MSFTNGP10.phx.gbl
    >Xref: cpmsftngxa09.phx.gbl microsoft.public.dotnet.framework.aspnet:32022
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >
    >I did tell you how to do this. I said to call the Read method, and I
    >explained its return values and what it means.
    >
    >For more information, please look up the OleDbDataReader class in the
    >documentation.
    >
    >"Kathy Burke" <kathyburke40@attbi.com> wrote in message
    >news:uyW6ILWQDHA.2636@TK2MSFTNGP10.phx.gbl...
    >> Thanks, Marina,
    >>
    >> Could you please tell me HOW to get to the first row. The only time I've
    >> used datareader was to populate listboxes, can't figure out how to get
    >> just the one value.
    >>
    >> Thanks.
    >>
    >> KathyBurke
    >>
    >> *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    >> Don't just participate in USENET...get rewarded for it!
    >
    >
    >
    Jim Blizzard [MSFT] Guest

  8. #7

    Default Re: Applying datareader results to label or text???

    Thank you all for the help, I am now getting the reader results (yeah!),
    but still doing something wrong comparing it to the password textbox.

    David said "you cannot use
    the .Text property on a text box that is type 'password'.
    You can use the .Attribute.item("Value")= ... to set it
    though..."

    I must be doing this wrong (haven't dealt with attributes yet...) so
    please tell me where this line is wrong...?

    thanks again, kathy

    dbpass is the textbox set to password format:

    dbPass.Attributes.Item("Value") = Rdr3("Password") OR...
    dbPass.Attributes.Item("Password") = Rdr3("Password")

    sorry if i'm being totally stupid. I also can't find a good reference on
    what the available attributes are...any suggestions?


    KathyBurke

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Kathy Burke Guest

  9. #8

    Default Applying datareader results to label or text???

    YA KNOW KATHY,

    if you post here for an answer, do us the courtesy of at
    least READING OUR RESPONSES.

    You were given a complete answer, and yet, you ask the
    SAME QUESTIONS AGAIN - How do I read, How do I use the
    text field in a password control.

    It's really aggravating.

    >-----Original Message-----
    >Please tell me where I'm going wrong on the marked
    lines***. The code
    >is fine to that point. I've only used this code to
    populate
    >dropdownlists using databind to the control. Here, I just
    need to get
    >the one field associated with a variable or a label
    control.
    >
    >THANKS!
    >
    >kathy
    >
    >Dim Conn3 As New OleDbConnection()
    >Dim Rdr3 As OleDbDataReader
    >Dim strSQL3 As String = "SELECT Password FROM tblUsers
    WHERE
    >([UserName] = @UserName)"
    >Dim Cmd3 As New OleDbCommand(strSQL3, Conn3)
    >Conn3 = New OleDbConnection(strConn)
    >Dim prmUserName As OleDbParameter = New OleDbParameter
    ("@UserName",
    >OleDbType.VarChar, 50)
    >prmUserName.Value = cboUser.SelectedItem.Value
    >Cmd3.Parameters.Add(prmUserName)
    >Cmd3.Connection = Conn3
    >Conn3.Open()
    >Rdr3 = Cmd3.ExecuteReader()
    >dbPass.Text = Rdr3("Password") '***what is
    wrong with this
    >line?
    >Dim strPass As String = Rdr3("Password") '***or what is
    wrong with
    >this line?
    >Rdr3.Close()
    >Conn3.Close()
    >.
    >
    David Waz... Guest

  10. #9

    Default Re: Applying datareader results to label or text???

    YA KNOW DAVID,

    That's a bit MEAN! I did read the responses, but I am very new to
    asp.net and sometimes it doesn't sink in without an example. Sometimes
    the experienced people (e.g., you and Marina) respond with a direction
    of "do this" and sometimes that doesn't translate if the person hasn't
    done that before. But let me assure you, I have read several books but
    they tend to blur after a while. Real world examples work best for some
    people (including me, unfortunately). When I went back and read Marina's
    first response, I realized what I had missed.

    And I did try your response control.attributes.item("value") =
    reader_result, but I kept getting an unknown page error...therefore, I
    asked again. I worked around it by assigning the reader_result to a
    textbox and doing a compare validator...I'm sure that's not the best way
    to go.

    All that being said, I think it's great that you and other very
    experienced users help those less fortunate via this group. I certainly
    didn't mean to piss you off.

    Kathy



    KathyBurke

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Kathy Burke Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139