Results 1 to 18 of 18

Thread: [RESOLVED] Retrieve multiple records from ... where ...

  1. #1

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Resolved [RESOLVED] Retrieve multiple records from ... where ...

    Ola,

    I know this is basic, but my mind is totally blanc. I'm trying to retrieve all records from a table with a specific code.

    Code:
    Dim cmd As New MySqlCommand("SELECT myValueRow FROM myTable WHERE  searchRow = 'test'", myconnection)
    myreader = cm.executereader
    
    while reader.read
       debug.print(.....)  '   eeeh.... can't use executescaler, want all of them. "reader.item("myvaluerow") also returns one value
    end while
    Thanks in advance.
    Last edited by Radjesh Klauke; Jun 15th, 2012 at 07:49 AM.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Retrieve multiple records from ... where ...

    vbnet Code:
    1. myreader = cm.executereader
    Shouldn't that be:-
    vbnet Code:
    1. myreader = cmd.executereader
    ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Retrieve multiple records from ... where ...

    Yeah, was a typo. Sorry. I typed it manually.
    but not solving the issue


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  4. #4
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Retrieve multiple records from ... where ...

    when SQL is guided with a criteria = test , i think that is y all records are not been returned
    "SELECT myValueRow FROM myTable WHERE searchRow = 'test'"
    ultimately it is SQL which is extracts the rows of data, which is the matter of concern in this case.

    next is lets say SQL returns all your needy data, but the code is not returning
    of course your code returns all the data, but can be red one row only at a time, since you are using datareader.
    if you need all at once then use dataadapter + dataset to return a datatable

    what exactly you are looking for
    yours mk me rn
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  5. #5

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Retrieve multiple records from ... where ...

    I really don't understand what you are saying m8. Sorry.

    Let's say that this is my table
    Code:
    1    radjesh   25
    2    niya      25
    3    m_m_r     26
    I want to retrieve the people who have an "id" of 25, which should result in "radjesh" and "niya". With the code I used I only got "radjesh".
    I hpe this example is a bit more clear.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Retrieve multiple records from ... where ...

    It would help if you showed the actual code. There may be a problem that does not show up in the abreviated version of the first post.

  7. #7

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Retrieve multiple records from ... where ...

    Uuuuh... That is actually the whole code. Nothing fancy.

    vb.net Code:
    1. conn.open
    2. Dim x_id As String = x_tree.SelectedNode.Cells(3).Text
    3. Dim cmd As New MySqlCommand("SELECT _pl FROM list WHERE gem_id = " & x_id, conn)
    4. Dim reader As MySqlDataReader
    5. reader = cmd_gemplaats.ExecuteReader
    6. While reader.Read
    7.    'debug.print(..)
    8. End While
    9. conn.close


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  8. #8
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Retrieve multiple records from ... where ...

    Oh i got it rajesh, are you using MySQL
    i feel nothing wrong with the SQL or your code, issue is at the table data

    Check (1) what rows is being returned if the query is run in the database it self
    SELECT myValueRow FROM myTable WHERE searchRow = 'test'
    GROUP BY myValueRow
    is the query returning more than 1 row of id = 25 ?
    please check
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  9. #9
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Retrieve multiple records from ... where ...

    That query looks right to me. It seems you are searching for a string. Perhaps its a case-sensitivity issue or there is a space in one of the strings that cause the Where to evaluate it to false thus not return it.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  10. #10

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Retrieve multiple records from ... where ...

    Well, it is was a "space" issue, then it wouldn't return a single value/record, but it does return one when I use reader.ExecuteScaler.ToString.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  11. #11
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Retrieve multiple records from ... where ...

    If that is the actual code
    Code:
    While reader.Read
       'debug.print(..)
    End While
    There is nothing for it to do.

    I thought perhaps there was something in the While that was causing an expected result but what you show here there is nothing there at all.

  12. #12

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Retrieve multiple records from ... where ...

    In my OP I told what I tried. This is simply what I tried. Come one... I'm not that stupid (I think...)


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  13. #13
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Retrieve multiple records from ... where ...

    Sorry, You never know though I have seen and even experienced some pretty odd things, even from top notch programmers.

  14. #14
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Retrieve multiple records from ... where ...

    Ok Ok
    but radjesh out of curiosity,, i insist that what is the out put of this query if runs with in your MySQL server command prompt
    SELECT myValueRow FROM myTable WHERE searchRow = 'test'
    GROUP BY myValueRow
    returns correct out put ?
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  15. #15
    Hyperactive Member marniel647's Avatar
    Join Date
    Aug 2010
    Location
    MSDN Library
    Posts
    259

    Re: Retrieve multiple records from ... where ...

    Code:
    conn.open
    
    Dim x_id As String = x_tree.SelectedNode.Cells(3).Text
    
    Dim cmd As New MySqlCommand("SELECT _pl FROM list WHERE gem_id = "' & x_id & '", conn)
    
    Dim reader As MySqlDataReader
    
    reader = cmd_gemplaats.ExecuteReader
    
    While reader.Read
    
       'debug.print(..)
    
    End While
    
    conn.close
    try this.

  16. #16

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Retrieve multiple records from ... where ...

    Sorry for the late reply. Had a friend over.

    I tried it again with the same code and had a good and long look again. Suddenly I saw that the code was correct all the way. The debug.print returned all the values, but the real issue seems to be the way I want to present them.

    I have an rtb on my form where I want to show the returned values.

    This show all the values:
    rtb.text = reader.item("column1").tostring (e.g. radjesh / m_m_r / datamiser / niya)

    ...But this only shows the last value only:
    rtb.text = "testing " & reader.item("column1").tostring (niya)

    Why does this happen and how do I fix this?


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  17. #17
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Retrieve multiple records from ... where ...

    .text property of the RTB will set only the current text to display , it won't write or add the new line
    try .appendtext property
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  18. #18

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Retrieve multiple records from ... where ...

    Ah! Yes! the AppendText. Totally forgot about that one. Thanks m8.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

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