类型“System.Data.SqlClient.SqlDataReader"没有定义构造函数 [英] The type 'System.Data.SqlClient.SqlDataReader' has no constructors defined

查看:33
本文介绍了类型“System.Data.SqlClient.SqlDataReader"没有定义构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 SqlDataReader 时遇到问题.当我尝试运行页面时,我收到错误'System.Data.SqlClient.SqlDataReader' 类型没有定义构造函数".我的目的是在用户没有访问权限时返回字符串值 0,当用户进行评估时返回字符串值 1.下面是我的代码片段.

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;
}

推荐答案

尝试类似:

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 中的示例相同

I have changed your SqlDataReader instantiation to the line where you execute the query Same way like in this example from MSDN

http:///msdn.microsoft.com/es-es/library/system.data.sqlclient.sqldatareader(v=vs.110).aspx

这篇关于类型“System.Data.SqlClient.SqlDataReader"没有定义构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆