Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法在C#中用Dapper调用存储的MySQL过程include insert参数? public void插入器(string firstname、string lastname、string email、string password、int age) { 使用(IDbConnection connection=new MySql.Data.MySqlClient.MySqlConnection(Helper.CnnVal(“数据库”)) { 列表用户=新列表(); 添加(新用户{Firstname=Firstname,Lastname=Lastname,Email=Email,Password=Password,Age=Age}); 执行(“InsertUserProcedure”、@Firstname、@Lastname、@Email、@Password、@Age、users); } }_C#_Mysql_Dapper - Fatal编程技术网

有没有办法在C#中用Dapper调用存储的MySQL过程include insert参数? public void插入器(string firstname、string lastname、string email、string password、int age) { 使用(IDbConnection connection=new MySql.Data.MySqlClient.MySqlConnection(Helper.CnnVal(“数据库”)) { 列表用户=新列表(); 添加(新用户{Firstname=Firstname,Lastname=Lastname,Email=Email,Password=Password,Age=Age}); 执行(“InsertUserProcedure”、@Firstname、@Lastname、@Email、@Password、@Age、users); } }

有没有办法在C#中用Dapper调用存储的MySQL过程include insert参数? public void插入器(string firstname、string lastname、string email、string password、int age) { 使用(IDbConnection connection=new MySql.Data.MySqlClient.MySqlConnection(Helper.CnnVal(“数据库”)) { 列表用户=新列表(); 添加(新用户{Firstname=Firstname,Lastname=Lastname,Email=Email,Password=Password,Age=Age}); 执行(“InsertUserProcedure”、@Firstname、@Lastname、@Email、@Password、@Age、users); } },c#,mysql,dapper,C#,Mysql,Dapper,以下是适用于大多数ADO.NET提供程序的一般指南;它没有考虑任何MySQL特性或细微差别(因为我不是MySQL用户) 如果存储过程参数与用户上的属性完全匹配,那么您应该能够按照以下步骤进行操作: connection.Execute( “InsertUserProcedure”,用户,命令类型:commandType.StoredProcedure); 如果user上的属性多于存储过程所需的属性,那么一种方法是通过EXEC/调用来间接调用存储过程(作为CommandText,这是默认值):

以下是适用于大多数ADO.NET提供程序的一般指南;它没有考虑任何MySQL特性或细微差别(因为我不是MySQL用户)

如果存储过程参数与
用户
上的属性完全匹配,那么您应该能够按照以下步骤进行操作:

connection.Execute(
“InsertUserProcedure”,用户,命令类型:commandType.StoredProcedure);
如果
user
上的属性多于存储过程所需的属性,那么一种方法是通过
EXEC
/
调用来间接调用存储过程(作为
CommandText
,这是默认值):

connection.Execute(
“EXEC InsertUserProcedure@Firstname、@Lastname、@Email、@Password、@Age”,用户);
(或者与MySQL上的
CALL
相同,而不是
EXEC
,参见注释)

另一种方法是使用
Select
作为投影,允许直接使用存储过程,但限制传入的属性:

connection.Execute(“InsertUserProcedure”),用户。选择(u=>new{
u、 名字、姓氏、电子邮件、密码、年龄
},commandType:commandType.StoredProcess);

Hi marc存储过程参数与username上的属性完全匹配,但我将得到lastname列的错误信息null@Mily您是否指定了
commandType:commandType.StoredProcess
?如果我使用您的sec脚本,我会收到语法错误并要求检查MariaDb服务器version@Bradley这很有用,谢谢;我已经在教育部澄清了信息技术
public void InsertUser(string firstname, string lastname, string email, string password, int age)
{
    using (IDbConnection connection = new MySql.Data.MySqlClient.MySqlConnection(Helper.CnnVal("Database")))
    {
        List<user> users = new List<user>();
        users.Add(new user { Firstname = firstname, Lastname = lastname, Email = email, Password = password, Age = age });
        connection.Execute("InsertUserProcedure", @Firstname,@Lastname,@Email,@Password,@Age,users);
    }
}