简体   繁体   English

尝试使用dapper创建登录表单以连接到SQL,但我无法使DataAdapter正常工作

[英]Trying to create a login form using dapper to connect to SQL but I can't get the DataAdapter to work

Here is my code 这是我的代码

public class LoginFunction
{
    public DataTable User (string username, string pword)
    {
        using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(ConnectionHelper.CnnVal("GymDB")))
        {

            var query = ("Select * from [USER] where username = '{username}'  and password = '{pword}'");
            SqlDataAdapter sda = new SqlDataAdapter(query, connection);
            DataTable dtbl = new DataTable();
            sda.Fill(dtbl);



        }
    }
}

} }

The error im getting is "cannot convert from 'System.Data.IDbConnection' to 'string'". 我收到的错误是“无法从'System.Data.IDbConnection'转换为'string'”。

The error is with the connection argument for SqlDataAdapter - I thought this would get the SQL connection from the IDbConnection. 错误与SqlDataAdapter的连接参数有关-我认为这将从IDbConnection获得SQL连接。

I'm sorry I can not comment yet. 对不起,我无法发表评论。

Try to change IDbConnection to SqlConnection and var query to string query and take away the parenthesis. 尝试将IDbConnection更改为SqlConnection ,将var query更改为string query并删除括号。

See if it works!? 看看是否有效!?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用CSHTML做一个非常基本的登录页面,但是我的if语句无法正常工作 - Trying to do a very basic login page using CSHTML but I can't get my if statement to work correctly 当我可以使用具有相同登录名的SQL Server Management Studio进行连接时,为什么我的应用程序不连接到SQL Server数据库? - Why won't my application connect to SQL Server database when I can connect using SQL Server Management Studio with the same login? 无法在Dapper中使用多重映射 - Can't get multi-mapping to work in Dapper 无法使Dapper正确处理SQL RowVersion - Can't get Dapper to handle SQL RowVersion properly 像DataAdapter这样的Dapper命令 - Dapper command like DataAdapter 无法使用WPF Datagrid和DataAdapter更新本地数据库 - Can't update Local Database using WPF Datagrid & DataAdapter 尝试使用StreamWriter和StreamReader创建登录系统,但是不起作用? - Trying to use StreamWriter and StreamReader to create a login system but it doesn't work? 我可以使用DataAdapter C#填充列表吗? - Can I Fill a List using a DataAdapter C# 我无法通过普通登录使用表单身份验证进行身份验证 - I can't get authenticated using Forms Authentication with common login 如果未安装SQL Server 2005,是否可以创建并连接到SQL Server CE数据库? - Can I create and connect to a SQL Server CE database if SQL Server 2005 isn't installed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM