我有SqlDataReader的问题。尝试运行页面时,出现错误“类型'System.Data.SqlClient.SqlDataReader'没有定义的构造函数”。我的目的是在用户没有访问权限时返回字符串值0,在用户评估时返回字符串值1。以下是我的代码段。
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;
}
最佳答案
尝试类似的东西:
public string CheckAssess(string emailAddress, string columnName)
{
string chkAssess;
string MgrAssessQry = "SELECT '"+columnName+"' FROM tblAllUsers";
MgrAssessQry += " WHERE email ='" + emailAddress + "'";
SqlCommand cmdReadAssess = new SqlCommand(MgrAssessQry, cn);
cn.Open();
SqlDataReader readAssess = cmdReadAssess.ExecuteReader();
while(readAssess.Read())
{
// Add the rows
chkAssess = readAssess["IsAssessMgr"].ToString();
}
return chkAssess;
}
我已将SqlDataReader实例化更改为执行查询的行
与本例中的MSDN一样
http://msdn.microsoft.com/es-es/library/system.data.sqlclient.sqldatareader(v=vs.110).aspx
关于c# - 类型'System.Data.SqlClient.SqlDataReader'没有定义的构造函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22169519/