Invalid attempt to call MetaData when reader is closed
<pre><code>try
{

    SqlCommand cmd = con.CreateCommand(); // connection string is correct, work great with other functions.

    cmd.CommandText = "Select * from BOOKS where ac_no='a10001'";
    cmd.CommandType = CommandType.Text;
    con.Open();
    SqlDataReader data = cmd.ExecuteReader();

    int Ac_no = data.GetOrdinal("Ac_no");
    int Issn = data.GetOrdinal("Issn");
    int Isbn = data.GetOrdinal("Isbn");
    int Title = data.GetOrdinal("Title");
    int Author = data.GetOrdinal("Author");
    int Publisher = data.GetOrdinal("Publisher");
    int Edition = data.GetOrdinal("Edition");
    int Year = data.GetOrdinal("Year");
    int Price = data.GetOrdinal("Price");
    int Available = data.GetOrdinal("Available");
    int Rack_no = data.GetOrdinal("Rack_no");

    data.Read();

    /* works fine when label is used to display data */
    /* 

    lbl_Acno.Text = data.GetValue(Ac_no).ToString();
    lbl_Issn.Text = data.GetValue(Issn).ToString();
    lbl_Isbn.Text = data.GetValue(Isbn).ToString();
    lbl_Title.Text = data.GetValue(Title).ToString();
    lbl_Author.Text = data.GetValue(Author).ToString();
    lbl_Pub.Text = data.GetValue(Publisher).ToString();
    lbl_Edition.Text = data.GetValue(Edition).ToString();
    lbl_Book_Year.Text = data.GetValue(Year).ToString();

    */

    /* creates error when textboxes are used to display data */

    txt_acc_acno.Text = data.GetValue(Ac_no).ToString();
    txt_acc_issn.Text = data.GetValue(Issn).ToString();
    txt_acc_isbn.Text = data.GetValue(Isbn).ToString();
    txt_acc_title.Text = data.GetValue(Title).ToString();
    txt_acc_auth.Text = data.GetValue(Author).ToString();
    txt_acc_publisher.Text = data.GetValue(Publisher).ToString();
    txt_acc_edition.Text = data.GetValue(Edition).ToString();
    txt_acc_year.Text = data.GetValue(Year).ToString();
    txt_acc_price.Text = data.GetValue(Price).ToString();
    txt_acc_rack.Text = data.GetValue(Rack_no).ToString();

    con.Close();
}

catch (Exception e1)

{

    MessageBox.Show(e1.Message);

}
</code></pre>

<p>My problem is that, when i use the labels to display data then the data is displayed, but textboxes doesn't show data, instead an exception is generated "Invalid attempt to call MetaData when reader is closed."</p>

<p>the connection string is correct.</p>

<p>What's the correct method to display data (in textboxes) which is retrieved from database.</p>
