[英]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.