下面代码能实现把数组 WELL_ID,REF_WELL_ID  插入到 td_bas_well 表中,
请问各位,怎样以同样的方式实现更新呢?
网上说可以执行更新,但是我试了很多次都失败了,
这是网址:http://blog.csdn.net/hawksoft/article/details/7528384            string[] WELL_ID = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
            string[] REF_WELL_ID = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };            OracleCommand theCmmd = new OracleCommand("insert into td_bas_well (WELL_ID,REF_WELL_ID) values(:WELL_ID,:REF_WELL_ID)", ConnPool.GetTargetConn().Conn);
            theCmmd.ArrayBindCount = WELL_ID.Length;//关键点  
            theCmmd.Parameters.Add(new OracleParameter("WELL_ID", OracleDbType.Varchar2, WELL_ID, System.Data.ParameterDirection.Input));
            theCmmd.Parameters.Add(new OracleParameter("REF_WELL_ID", OracleDbType.Varchar2, REF_WELL_ID, System.Data.ParameterDirection.Input));
            int count = theCmmd.ExecuteNonQuery();

解决方案 »

  1.   

    这是我改后的Update代码
    可是返回值为0,百思不得其解            string[] WELL_ID = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
                string[] REF_WELL_ID = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };            OracleCommand theCmmd = new OracleCommand("update td_bas_well set REF_WELL_ID = :REF_WELL_ID where WELL_ID = :WELL_ID", ConnPool.GetTargetConn().Conn);
                theCmmd.ArrayBindCount = WELL_ID.Length;//关键点  
                theCmmd.Parameters.Add(new OracleParameter("WELL_ID", OracleDbType.Varchar2, WELL_ID, System.Data.ParameterDirection.Input));
                theCmmd.Parameters.Add(new OracleParameter("REF_WELL_ID", OracleDbType.Varchar2, REF_WELL_ID, System.Data.ParameterDirection.Input));
                int count = theCmmd.ExecuteNonQuery();
      

  2.   

    关键点不是那个ArrayBindCount,而是那个字符串数组的给定,由于最终传说的是字节数组,而字节数组是没有字符串的分割标志的,它不知道数组中每个字符串有多长,那么它就根据字符串数组的长度(ArrayBindCount指定),自动推测每个字符串的长度(定长),但是你给的字符串长短不一(那个“10”是2位的),因此怎么都不可能成功了。
      

  3.   


    你好,你的意思是只要把
     theCmmd.Parameters.Add(new OracleParameter("REF_WELL_ID", OracleDbType.Varchar2, REF_WELL_ID, System.Data.ParameterDirection.Input));
    改成:

    OracleParameter op = new OracleParameter("REF_WELL_ID", OracleDbType.Varchar2, REF_WELL_ID, System.Data.ParameterDirection.Input);
    op.ArrayBindSize = new int []{2,2,2,2,2,2,2,2,2,2};
    theCmmd.Parameters.Add(op);

    可是即使给OracleParameter 设置了ArrayBindSize ,也执行不了啊?
      

  4.   

    错了,我的意思是,那个
    string[] WELL_ID = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
    string[] REF_WELL_ID = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
    要改为定长的字符串,比如都2位,不足补空格:
    string[] WELL_ID = new string[] { "1 ", "2 ", "3 ", "4 ", "5 ", "6 ", "7 ", "8 ", "9 ", "10" };
    你也可以试试指定OracleParameter的Size属性,但总之定长是必须的。而那个ArrayBindSize必须是int类型的,没让你用数组。
      

  5.   

    由于官方只给了int[]类型的参数举例,而没有给varchar2类型的参数类型,而我也没有用过这中怪异的方式,所以具体测试你得自己来,对于非定长数据类型,处理方式只有文字性描述而没有示例,只能自己测试了,你要是只想成功运行一次,将参数改为定长数据类型,应该能成功。
      

  6.   


    可是我执行insert成功了啊?下面是代码,插入的也是string[]型的,类型也是Varchar2,成功运行,并返回结果10,这样是怎么回事儿?是不是问题出现在其他地方?麻烦了            string[] WELL_ID = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
                string[] REF_WELL_ID = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
                OracleCommand theCmmd = new OracleCommand("insert into td_bas_well (WELL_ID,REF_WELL_ID) values(:WELL_ID,:REF_WELL_ID)", ConnPool.GetTargetConn().Conn);
                theCmmd.ArrayBindCount = WELL_ID.Length;//关键点
                theCmmd.Parameters.Add(new OracleParameter("WELL_ID", OracleDbType.Varchar2, WELL_ID, System.Data.ParameterDirection.Input));
                theCmmd.Parameters.Add(new OracleParameter("REF_WELL_ID", OracleDbType.Varchar2, REF_WELL_ID, System.Data.ParameterDirection.Input));
      

  7.   

    你INSERT和UPDATE的SQL语句难道是一样的?顶楼还说那样执行不行,现在又可以了,我真搞不懂你的问题代码倒底是哪个了。
      

  8.   

    以下是Insert,插入成功
                string[] WELL_ID = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
                string[] REF_WELL_ID = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
                OracleCommand theCmmd = new OracleCommand("insert into td_bas_well (WELL_ID,REF_WELL_ID) values(:WELL_ID,:REF_WELL_ID)", ConnPool.GetTargetConn().Conn);
                theCmmd.ArrayBindCount = WELL_ID.Length;//关键点
                theCmmd.Parameters.Add(new OracleParameter("WELL_ID", OracleDbType.Varchar2, WELL_ID, System.Data.ParameterDirection.Input));
                theCmmd.Parameters.Add(new OracleParameter("REF_WELL_ID", OracleDbType.Varchar2, REF_WELL_ID, System.Data.ParameterDirection.Input));
    在以下是更新,更新失败:
                    string[] WELL_ID = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
                    string[] REF_WELL_ID = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };                OracleCommand cmd = new OracleCommand("update td_bas_well set REF_WELL_ID = :REF_WELL_ID where WELL_ID = :WELL_ID", ConnPool.GetTargetConn().Conn);
                    cmd.ArrayBindCount = WELL_ID.Length;
                    cmd.Parameters.Add(new Oracle.DataAccess.Client.OracleParameter("REF_WELL_ID",OracleDbType.Varchar2));
                    cmd.Parameters["REF_WELL_ID"].Direction = System.Data.ParameterDirection.Input;
                    cmd.Parameters["REF_WELL_ID"].Value = REF_WELL_ID;
                    cmd.Parameters.Add(new Oracle.DataAccess.Client.OracleParameter("WELL_ID", OracleDbType.Char));
                    cmd.Parameters["WELL_ID"].Direction = System.Data.ParameterDirection.Input;
                    cmd.Parameters["WELL_ID"].Value = WELL_ID;
                    int i = cmd.ExecuteNonQuery();
      

  9.   

    对了如果以后有人碰到了相同的问题,还有一点要提醒大家:
    在创建参数时,参数顺序必须与SQL语句的顺序相同
    否则不会执行,且会返回0