I'm coding button which name 'Load'. I coded it like this,

            Using cmd = New MySqlCommand(Query, con)
                Query = "SELECT first_name FROM custormer WHERE custormer_id='" & txtcustormeridforloanform.Text & "'"
                dr = cmd.ExecuteReader()
                While dr.Read()
                    Me.txtcustormername.Text = Convert.ToString(dr("first_name"))
                End While
            End Using
        Catch ex As Exception
        End Try

I want to do this, there is text box name txtcustormer_id. If I type custormer id and click load button, I want to show custormer name to txtcustormer_name text box. but unfortunately firstly it give
The commandText property has not been properly initialized.
and after i click ok button on error message and again click load button it show correct custormer name. but second time I enter another custormer id and click load button. it show this error mesasge,
There is already an open datareader associated with this connection which must be closed first.
Can anyone help me ?

2 Years
Discussion Span
Last Post by Reverend Jim

At the time you do

Using cmd = New MySqlCommand(Query, con)

Query does not have a value. Assign the query string to Query prior to that statement.


I assign query as public variable. is that you mean ?


It doesn't matter whether it is public or private as long as it is in scope when you use it. Have a look at this code snippet. Note that at the end of the loop I do


once I am done reading the data. It's a good idea to keep things open for as short a time as possible. Similarly, make the scope of variables as restrictive as possible. The examples in the code snippet use MSSQL but the sequence of operations will be the same for MySQL.

Edited by Reverend Jim


hey where can I contact you ?


can I message you via daniweb ? where ?
I'm looking for conatct you with quick :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.