Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 942945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:21:15+00:00 2026-05-15T22:21:15+00:00

Please help, how do I really use data reader in vb.net. I’m using odbc

  • 0

Please help, how do I really use data reader in vb.net. I’m using odbc to connect mysql and vb.net.
Function I declared on a module:

Public Function form2search(ByVal drugname As String) As OdbcDataReader

        cmd.CommandText = "SELECT *  FROM drug WHERE Drug_name LIKE'%" & drugname & "' "
        Return cmd.ExecuteReader

    End Function

text_changed event:

con.drugname=textBoxdrugname.text
     Dim rdr As Odbc.OdbcDataReader
            rdr = con.form2search(drugname)
        if rdr.hasrows=true then
        rdr.read()

        TextBoxdrugname.Text = rdr("Drug_name").ToString
                        TextBoxdrugcode.Text = rdr("Drug_code").ToString
                        drugtype.Text = rdr("Drug_type").ToString

        end if

I see a result, but it only loads the first item on the database. I’ve put this code in the text_changed event. What’s the proper way of doing this? And what’s wrong with the 2nd code, why is it only loading the first data

As you can see the con is the module where I declared the function. Then I created an object of it in the form.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:21:16+00:00Added an answer on May 15, 2026 at 10:21 pm

    The DataReader is a low level implementation that does not support navigation and only reads a single row every time you call

    reader.Read()
    

    For a Windows Forms app you probably should use a DataSet / DataTable approach or a ORM. And you should consider using the mysql connector net over the odbc driver. It is available at mysql.com.

    Here is a little demo code:

    dim table as new DataTable("table1")
    
    ' Create a Connection
    using conn as new MysqlConnection("...connectionstring")
        conn.Open() ' Open it
    
        ' Create a new Command Object
        using cmd as new MysqlCommand("SELECT * FROM table", conn)
    
            ' Create a DataAdapter
            ' A DataAdapter can fill a DataSet or DataTable
            ' and if you use it with a CommandBuilder it also
            ' can persist the changes back to the DB with da.Update(...)
            using da as new MysqlDataAdapter(cmd)
                da.Fill(table) ' Fill the table
            end using
    
        end using
    end using
    
    ' A Binding Source allows record navigation
    dim bs as new BindingSource(table, nothing)
    
    ' You can bind virtually every property (most common are "text" "checked" or "visible"
    ' of a windows.forms control to a DataSource
    ' like a DataTable or even plain objects
    textBox1.DataBindings.Add("Text", bs, "columnName")
    
    ' Now you can navigate your data
    bs.MoveNext()
    
    ' Even a ComboBox can be bound to a List and display the related value
    ' of your current row
    comboBox1.DataSource = table2
    comboBox1.DisplayMember = "name"
    comboBox1.ValueMember = "id"
    
    comboBox1.DataBindings.Add("SelectedValue", bs, "id")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me to improve the following script: http://jsfiddle.net/n9BkM/8/ I need the following fucntionality:
I really need your help. I have a database with latitude and longitude data,
I coule really use some help. I need to post the new name of
I wonder whether someone can help me please. I'm using the code below to
Can you please help me understand the adapter with custom data : I was
firstly please excuse my relative inexperience with Hibernate I’ve only really been using it
Please help me somebody to convert unicodestring into string This is how i am
Please help me with this update query. I COMPLETELY understand how redundant this is
please help me arrange these 3 buttons horizontally like this photoshopped image: Please take
please help me. I want know about what types of flags to run an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.