1.执行无参数sql:
string sql = "select * from IntegralInfo where convert(nvarchar,getdate(),23)=‘{0}‘ and status=1 and userinfoid=‘{1}‘"; sql = string.Format(sql, DateTime.Now.ToString("yyyy-MM-dd"), uid); var IntegralInfoObj = db.Database.SqlQuery<IntegralInfo>(sql).FirstOrDefault();
2.执行有参数sql:
var IntegralInfoObj = db.Database.SqlQuery<IntegralInfo>("select * from IntegralInfo where convert(nvarchar,getdate(),23)[email protected] and status=1 and [email protected]", new SqlParameter("@time", DateTime.Now.ToString("yyyy-MM-dd")), new SqlParameter("@uid", uid)).FirstOrDefault();
时间: 2024-10-24 11:43:27