string sql = @" SELECT B.[FId], A.[FileTypeNo], A.[FtypeName], A.[FtypeId], A.[ProcessName], A.[ProcessId], B.[InstanceId], B.[Status] FROM [Process] AS A INNER JOIN [ProcessInstance] AS B ON A.[ProcessId]=B.[ProcessId] WHERE B.[UserId]=@userId AND A.[FileTypeNo]=@FileTypeNo"; using(DbHelper<Process> pDb = new DbHelper<Process>()) { var userNameParam = new System.Data.SqlClient.SqlParameter { ParameterName = "@userId", Value = userId }; var fileTypeNoParam = new System.Data.SqlClient.SqlParameter { ParameterName = "@fileTypeNo", Value = fileTypeNo }; var info = pDb.Database.SqlQuery<ProcessAllInfoDto>(sql, userNameParam, fileTypeNoParam).FirstOrDefault(); return info; }
SQL查询与参数化示例
本文介绍了一个使用参数化SQL查询的C#代码示例,该查询从两个数据库表中联接数据,并通过特定的用户ID和文件类型编号筛选记录。示例展示了如何创建SqlParameter对象来传递查询参数,以及如何使用DbHelper类执行SQL查询并获取第一条结果。
1739

被折叠的 条评论
为什么被折叠?



