您的位置:程序门 -> .net技术 -> c#



c#取得sql返回值的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


c#取得sql返回值的问题
发表于:2008-01-21 18:03:00 楼主
请教个问题,我想往一张oracle表中插入一个值,然后返回该条记录的   fid(一个字段).调试后,发现下面的代码段,不能实现需要的功能,请大家帮忙看看

界面过程:
strsql   =   @"declare
    ffid   number;
begin
    insert   into   tattr_dj_landbook
        (f_serial_no,   f_certificate_no,   f_land_loc)
    values
        ('200712190010055',
          '成国用(房改转)字第53277号',
          '金牛区黄忠小区二期14幢4单元3楼6号')
    returning   fid   into   ffid;
end;";

                                        oracleparameter   op1   =   new   oracleparameter();
                                        op1.parametername   =   "ffid";
                                        op1.oracletype   =   oracletype.number;
                                        op1.size   =   10;

后台过程:
public   static   outtype   dowithreturnfromoracle <outtype> (string   procedure,   string   parameter_in,   oracleparameter   parameter_out,   bool   isprocedure,   string   configname)
                {
                        oracleconnection   ocn_oracle   =   null;
                        ocn_oracle   =   new   oracleconnection(configurationmanager.connectionstrings[configname].tostring());

                        oraclecommand   oc_oracle   =   getoraclecommand(procedure,   parameter_in,   isprocedure,   ocn_oracle);
                       
                        parameter_out.direction   =   parameterdirection.output;
                        ocn_oracle.open();
                        oc_oracle.EXECutenonquery();
                        ocn_oracle.close();
                        //ocn_oracle.dispose();
                        return   (outtype)convert.changetype(parameter_out.value,   typeof(outtype));
                }

                static   oraclecommand   getoraclecommand(string   procedure,   string   parameter,   bool   isprocedure,   oracleconnection   s_ocn)
                {
                        oraclecommand   oc   =   null;
                        try
                        {
                                oc   =   new   oraclecommand(procedure,   s_ocn);
                                oracleparameter   odp   =   new   oracleparameter();
                                if   (!string.isnullorempty(parameter))
                                {
                                        if   (parameter.indexof(',')   !=   -1)
                                        {
                                                string[]   paramters   =   parameter.split(',');
                                                string[]   cols   =   procedure.split(':');
                                                list <string>   colnames   =   new   list <string> ();

                                                parallel.for(1,   cols.getupperbound(0),   i   =>
                                                {
                                                        for   (int   j   =   1;   j   <=   cols.getupperbound(0);   j++)
                                                        {
                                                                string[]   subcols   =   cols[j].trimstart('   ').split('   ');
                                                                colnames.add(subcols[0]);
                                                        }
                                                });

                                                parallel.for(1,   paramters.getupperbound(0),   i   =>
                                                {
                                                        for   (int   j   =   0;   j   <=   paramters.getupperbound(0);   i++)
                                                        {
                                                                oc.parameters.addwithvalue(colnames[j],   paramters[j]);
                                                        }
                                                });
                                        }
                                        else
                                        {
                                                string[]   cols   =   procedure.split(':');
                                                oc.parameters.addwithvalue(cols[cols.getupperbound(0)].trimstart('   '),   parameter);
                                        }
                                }

                                if   (isprocedure)
                                {
                                        oc.commandtype   =   commandtype.storedprocedure;
                                }
                                else
                                {
                                        oc.commandtype   =   commandtype.text;
                                }
                        }
                        catch
                        {
                                throw   new   exception();
                        }
                        return   oc;
                }
发表于:2008-01-22 08:54:181楼 得分:0
返回值   始终为空
发表于:2008-01-22 09:10:552楼 得分:0
oraclecommand       oc       =       null;  
发表于:2008-01-23 08:55:553楼 得分:0
大家帮忙看看
发表于:2008-01-23 10:13:014楼 得分:0
关注!~


快速检索

最新资讯
热门点击