如何在C Sharp中编写SQL Querry代码 [英] how to write sql querry code in c sharp

查看:117
本文介绍了如何在C Sharp中编写SQL Querry代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select distinct
        sec_mrf_details.fnid_int
from    sec_umrf_details
        left join sec_mrf_details on sec_umrf_details.mrfno_nu = sec_mrf_details.mrfno_nu
        left join sec_functions on  sec_functions.fnid_int = sec_mrf_details.fnid_int
        left join sec_roles on sec_roles.roleid_int = sec_mrf_details.roleid_int
        left join sec_modules on sec_modules.modid_int = sec_mrf_details.modid_int
        left join sec_users on  sec_users.userid_vc = sec_umrf_details.userid_vc
where   sec_umrf_details.deleted_int=0
        and sec_umrf_details.userid_vc='i-jadoon' and sec_mrf_details.modid_int = 11

推荐答案

我怀疑您想在此代码中为"i-jadoon"和"11"设置值.如果是这样,则IMO的最佳方法是编写一个存储的proc并使用参数对其进行调用.您还可以使用参数化查询.您永远不要做的是直接在文本框等中的值上添加常量来构建字符串,因为这些值可能会被黑客入侵.
I suspect you want to set values for ''i-jadoon'' and ''11'' in this code. If so, the best way IMO is to write a stored proc and call it with parameters. You can also use a paramaterised query. What you should NEVER do, is build a string directly by adding constants to the values in textboxes, etc, as these can be hacked.


尝试使用此方法...

Try this one...

StringBuilder SQL = new StringBuilder("");
SQL.Append("select distinct sec_mrf_details.fnid_int from    sec_umrf_details ");
SQL.Append(" left join sec_mrf_details on sec_umrf_details.mrfno_nu = sec_mrf_details.mrfno_nu ");
SQL.Append("  left join sec_functions on  sec_functions.fnid_int = sec_mrf_details.fnid_int ");
SQL.Append("left join sec_roles on sec_roles.roleid_int = sec_mrf_details.roleid_int
 ");
SQL.Append(" left join sec_modules on sec_modules.modid_int = sec_mrf_details.modid_int ");
SQL.Append("left join sec_users on  sec_users.userid_vc = sec_umrf_details.userid_vc ");
SQL.Append("where   sec_umrf_details.deleted_int=0
        and sec_umrf_details.userid_vc='i-jadoon' and sec_mrf_details.modid_int = 11
 ");
string Query = string.Format(SQL.ToString());


您好,

取一个字符串并在上面分配给该字符串
定义sql命令并将该字符串传递给sqlcommand.

希望它对您有用.如果需要更多说明,请写评论.
谢谢

sanjeev
Hello,

take a string and assign above to that string
define the sql command and pass that string to sqlcommand.

hoping it will work for you.write comment if more clearification required.
thanks

sanjeev


这篇关于如何在C Sharp中编写SQL Querry代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆