如何将参数化查询作为查询返回参数值而不是(:i_GroupID)或(:i_DpIntID) [英] How to return parameterized query as query with parameters values and not(:i_GroupID)or(:i_DpIntID)

查看:91
本文介绍了如何将参数化查询作为查询返回参数值而不是(:i_GroupID)或(:i_DpIntID)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void UserRights_Details(string Module_Name, string eximorform, Page t_Page, string SelMode)
        {
            string sql;
            User_Rigths_Qry o_Qry_UserRights = new User_Rigths_Qry();

            sql = o_Qry_UserRights.qry_getUserRights(SessionCheck.s_sessiondpintind, SessionCheck.s_sessionusergroupid, Module_Name);

            DataSet ds;
            StringBuilder str = new StringBuilder();
            s_DSNSTR = utl_fnGetDSNStr(SessionCheck.s_sessiondpid);
            OledbConnect obj_oc = new OledbConnect(s_DSNSTR);
            ds = obj_oc.GetDataSet(s_DSNSTR, sql);


 //public string qry_getUserRights(int i_DpIntID, int i_GroupID, string Module_Name)
    //{
    //    StringBuilder strBuilder = new StringBuilder();
    //    strBuilder.Append(" SELECT A.UI_ACCESS, A.UI_ADD, A.UI_EDIT, A.UI_VIEW, C.MVIEW, C.MADD, C.MEDIT, C.MACCESS ");
    //    strBuilder.Append(" FROM DPSECURE_UI A, DPSECURE_UI_DPLIST D, USER_RIGHTS_MASTER B, USER_RIGHTS_MASTER_DETAIL C ");
    //    strBuilder.Append(" WHERE A.ID = D.DPSECURE_UI_ID AND ");
    //    strBuilder.Append(" D.ID = C.DPSECURE_UI_DPLIST_ID AND ");
    //    strBuilder.Append(" B.ID = C.USER_RIGHTS_MASTER_ID AND ");
    //    strBuilder.Append(" A.UI_MENU_NAME =:Module_Name AND ");
    //    strBuilder.Append(" B.GROUP_ID =:i_GroupID  AND D.DP_LIST_ID =:i_DpIntID ");

    //    s_dsnstr = o_Cls_Utility.utl_fnGetDSNStr(SessionCheck.s_sessiondpid);
    //    OracleConnect o_Cls_OracleConnect = new OracleConnect(s_dsnstr);
    //    o_Cls_OracleConnect.OracleCommand_PreInit(strBuilder.ToString());

    //    o_Cls_OracleConnect.Parameter_String("Module_Name", Module_Name);
    //    o_Cls_OracleConnect.Parameter_Int32("i_GroupID", i_GroupID);
    //    o_Cls_OracleConnect.Parameter_Int32("i_DpIntID", i_DpIntID);



    //    return strBuilder.ToString();
    //}



当我运行上面的代码时,我得到异常而不是所有变量都绑定。

in ds = obj_oc.GetDataSet(s_DSNSTR,sql);

查询为:


When i run above code i get exception not all variables bound.
in ds = obj_oc.GetDataSet(s_DSNSTR, sql);
The query is :

SELECT A.UI_ACCESS, A.UI_ADD, A.UI_EDIT, A.UI_VIEW, C.MVIEW, C.MADD, C.MEDIT, C.MACCESS  FROM DPSECURE_UI A, DPSECURE_UI_DPLIST D, USER_RIGHTS_MASTER B, USER_RIGHTS_MASTER_DETAIL C  WHERE A.ID = D.DPSECURE_UI_ID AND  D.ID = C.DPSECURE_UI_DPLIST_ID AND  B.ID = C.USER_RIGHTS_MASTER_ID AND  A.UI_MENU_NAME =:Module_Name AND  B.GROUP_ID =:i_GroupID  AND D.DP_LIST_ID =:i_DpIntID here there is no value

推荐答案

你必须访问以下页面...克服你的问题...... ...



链接会帮到你很多.....



http://office。 microsoft.com/en-in/access-help/use-a-parameter-to-make-a-query-ask-for-input-HA010341833.aspx [ ^ ]
you Have to visit on following page...overcome your issues......

link will help you a lot.....

http://office.microsoft.com/en-in/access-help/use-a-parameter-to-make-a-query-ask-for-input-HA010341833.aspx[^]


你展示了许多无用的代码,而且缺少了决定性的部分。您的代码中可能还缺少?

您在哪里创建命令对象?

您在哪里将参数值添加到命令中?

很确定你省略了至少一个参数(如果不是全部......)。
You show a lot of useless code, and the decisive parts a re missing. Perhaps also missing from your code?
Where do you create the command object?
Where do you add the parameter values to the command?
Pretty sure that you omitted at least one parameter (if not all...).


你的方法存在严重的问题。函数qry_getUserRights正在创建oracle连接对象和参数但尚未使用。该函数返回简单的SQL,稍后由obj_oc.GetDataSet函数执行。这个函数会创建sql中存在的参数吗?不,我不这么认为!



正确的方法是在qry_getUserRights函数中执行。
There is a serious issue in your approach. The function qry_getUserRights is creating oracle connection objects and parameters but has not been used. The function returns simple SQL which later executes by obj_oc.GetDataSet function. Will this function create parameters present in the sql? No i dont think so!

The correct approach would be to do the execution in qry_getUserRights function.


这篇关于如何将参数化查询作为查询返回参数值而不是(:i_GroupID)或(:i_DpIntID)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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