FreeSql
FreeSql copied to clipboard
存储过程、参数化、Output 使用总结
1、fsql.Ado.方法
var ps = new[]
{
new SqlParameter("@TableName", "tb1"),
new SqlParameter("@FInterID", System.Data.SqlDbType.Int)
};
//new SqlParameter 切换数据库不方便
ps[1].Direction = System.Data.ParameterDirection.Output;
fsql.Ado.ExecuteNonQuery(System.Data.CommandType.StoredProcedure, "dbo.GetICMaxNum", ps);
Console.WriteLine(ps[1].Value);
2、fsql.Ado.CommandFluent
DbParameter p2 = null; //Output
fsql.Ado.CommandFluent("dbo.GetICMaxNum")
.CommandType(CommandType.StoredProcedure)
.WithParameter("TableName", "tb1")
.WithParameter("FInterID", null, p =>
{
p2 = p;
p.DbType = DbType.Int32;
p.Direction = ParameterDirection.Output;
})
.ExecuteNonQuery();
Console.WriteLine(p2.Value);
3、其他姿势
DbParameter p3 = null;
fsql.Ado.CommandFluent("dbo.GetICMaxNum", new Dictionary<string, object>
{
["TableName"] = "tb1"
// 更多参数
})
.WithParameter("FInterID", null, p =>
{
p3 = p;
p.DbType = DbType.Int32;
p.Direction = ParameterDirection.Output;
})
.CommandType(CommandType.StoredProcedure)
.ExecuteNonQuery();
Console.WriteLine(p3.Value);
mysql 按着配置的会提示 Input string was not in a correct format.
@id ?id 这两种前缀都试试
@id ?id 这两种前缀都试试
只是第一种方式不可以,但是fluent方式可以
如何使用表值参数啊?