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.
System.Data.OleDb.OleDbConnection dbConnection = null;
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";
System.Data.OleDb.OleDbDataReader dr = null;
System.Data.OleDb.OleDbCommand dbCmd = null;
try
{
dbConnection = new System.Data.OleDb.OleDbConnection(MyCommon.GetDatabaseString("pts"));
dbConnection.Open();
dbCmd = new System.Data.OleDb.OleDbCommand(strSQL, dbConnection);
dr = dbCmd.ExecuteReader();
dgCertsAdmin.DataSource = dr;
dgCertsAdmin.DataBind()
}
finally
{
if (!dbConnection.Equals(null))
if (dbConnection.State.Equals(System.Data.ConnectionState.Open))
dbConnection.Close();
}
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.