I have issues with SqlDataReader. I get the error "The type 'System.Data.SqlClient.SqlDataReader' has no constructors defined" when I try running the page. My intention here is to return a string value 0 if the user has not had access or 1 when the user has assess. Below is my code snippet.
public string CheckAssess(string emailAddress, string columnName)
{
string chkAssess;
SqlDataReader readAssess;
readAssess = new SqlDataReader();
string MgrAssessQry = "SELECT '"+columnName+"' FROM tblAllUsers";
MgrAssessQry += " WHERE email ='" + emailAddress + "'";
SqlCommand cmdReadAssess = new SqlCommand(MgrAssessQry, cn);
cn.Open();
readAssess = cmdReadAssess.ExecuteReader();
while(readAssess.Read())
{
// Add the rows
chkAssess = readAssess["IsAssessMgr"].ToString();
}
return chkAssess;
}
SqlConnection,SqlCommandandSqlDataReaderare allIDisposableso each should be in ausingblock. Also, beware constructing queries using string concatenation because it makes your code vulnerable to SQL injection attacks: use SQL parameters.