Hi all,
Iam baffled at this - so basically, I want to get a set of records based on a query and then populate a combobox (with a field form the query) and then set the entire query result as a datagridview's datasource which displays all of its fields. Its to give the users 2 different views of their search to make it easier for them. here's the code:
So, when I set the SqlDataReader object to the gridview, it works fine. If I use it to read it , then it says its already closed, even though I have not. Can you find out where the error is or Iam missing something? Please help. Thank you.Code:SqlCommand cmd = new SqlCommand("Select rtrim(ndm_ndcode) as ndm_ndcode, rtrim(ndm_name) as ndm_name, rtrim(ndm_addr1) as ndm_addr1, rtrim(ndm_addr2) as ndm_addr2, rtrim(ndm_addr3) as ndm_addr3, rtrim(ndm_addr4) as ndm_addr4, rtrim(ndm_addr5) as ndm_addr5, rtrim(ndm_postcode) as ndm_postcode from ndmas where ndm_ndcode LIKE '" + sCustomer + "'", m_cnnMax); // it select x, y,z based on a condition on connection m_cnnMAX SqlDataReader rdr = cmd.ExecuteReader(); //set datagridview's datasource DataTable dt = new DataTable(); dt.Load(rdr); dgvwCustomerInfo.DataSource = dt; dgvwCustomerInfo.Refresh(); while (rdr.Read()) ////ERROR here - says reader closed! { cmbAccountCodes.Items.Add(rdr["ndm_ndcode"].ToString()); } rdr.Close(); rdr.Dispose(); cmd.Dispose();
Also, it would be very useful to you and me, if you can check out the site below. Thank you very much.


Reply With Quote

Bookmarks