ASP.NET 2.0 Invalid attempt to FieldCount when reader is closed

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2006
Posts: 4
Reputation: jclast is an unknown quantity at this point 
Solved Threads: 0
jclast jclast is offline Offline
Newbie Poster

ASP.NET 2.0 Invalid attempt to FieldCount when reader is closed

 
0
  #1
Nov 3rd, 2006
Hi, I'm new here, but I'm hoping that you guys can help me out.

I'm using ASP.NET 2.0 (C#), and I'm having a problem binding a DataReader to a DataGrid. If it makes any difference my IDE is MS Visual Web Developer 2005 Express Edition.

  1. System.Data.OleDb.OleDbConnection dbConnection = null;
  2. string strSQL = "SELECT certID, firstName, lastName, OACert, OCCert, initialCertDate, recertDate1, recertDate2, recertDate3, recertDate4, recertDate5, recertDate5, recertDate6, decertDate, decertReason FROM cert INNER JOIN users ON cert.userID = users.userID ORDER BY lastName ASC, firstName ASC";
  3. System.Data.OleDb.OleDbDataReader dr = null;
  4. System.Data.OleDb.OleDbCommand dbCmd = null;
  5. try
  6. {
  7. dbConnection = new System.Data.OleDb.OleDbConnection(MyCommon.GetDatabaseString("pts"));
  8. dbConnection.Open();
  9. dbCmd = new System.Data.OleDb.OleDbCommand(strSQL, dbConnection);
  10. dr = dbCmd.ExecuteReader();
  11. dgCertsAdmin.DataSource = dr;
  12. dgCertsAdmin.DataBind()
  13. }
  14. finally
  15. {
  16. if (!dbConnection.Equals(null))
  17. if (dbConnection.State.Equals(System.Data.ConnectionState.Open))
  18. dbConnection.Close();
  19. }
And when I try to run it I get the following error: "Invalid attempt to FieldCount when reader is closed."

Any ideas what I'm doing wrong? Thanks for the help.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 4
Reputation: jclast is an unknown quantity at this point 
Solved Threads: 0
jclast jclast is offline Offline
Newbie Poster

Re: ASP.NET 2.0 Invalid attempt to FieldCount when reader is closed

 
0
  #2
Nov 3rd, 2006
I gave up and rewrote the page.

The code works as I posted above.

Weird, but I'll take it.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC