MVC使用ODP.NET获得ORA-01840

时间:2014-08-18 22:17:08

标签: c# asp.net-mvc oracle plsql

我正在使用ODP.NET编写一个简单的MVC应用程序。我试图调用插入记录的Pl / Sql proc。

这是简单的Pl / Sql:

procedure spAddCountry(pGisRecid in country.GISRECID%type,
                     pCountryCode in country.COUNTRYCODE%type,
                     pCountryName in country.COUNTRYNAME%type,
                     pCurrencyCode in country.CURRENCYCODE%type,
                     pEUTerritory in country.EUTERRITORY%type,
                     pFatCAStatus  in country.FATCASTATUS%type,
                     pFATF in country.FATF%type,
                     pFSCountryCode in country.COUNTRYCODE%type,
                     pInsertedBy in country.INSERTEDBY%type,
                     pInsertedOn in country.INSERTEDON%type,
                     pLanguages in country.LANGUAGES%type,
                     pNCCT in country.NCCT%type) is
PRAGMA AUTONOMOUS_TRANSACTION;
begin
  INSERT INTO COUNTRY (GISRECID, COUNTRYCODE, COUNTRYNAME, CURRENCYCODE, 
         EUTERRITORY, FATCASTATUS, FATF, FSCOUNTRYCODE, INSERTEDBY, 
         INSERTEDON, LANGUAGES, NCCT)
  VALUES(pGISRECID, pCOUNTRYCODE, pCOUNTRYNAME, pCURRENCYCODE, 
         pEUTERRITORY, pFATCASTATUS, pFATF, pFSCOUNTRYCODE, pINSERTEDBY, 
         pINSERTEDON, pLANGUAGES, pNCCT);
  Commit;
end;

我无法将日期参数 pInsertedOn 传递给存储过程。我已经验证了Web表单成功检索表单数据并调用下面的AddCountry方法,该方法在填充所有parms后依次调用存储的proc,spAddCountry。

这是MVC C#代码的片段。

我收到以下异常:" ORA-01840输入值不足以支持日期格式"。

        public void AddCountry(Country aCountry)  //because the country object field names match the form field names they automatically get bound!!
        {
            string oradb = "Data Source=XYZ;User Id=XYZ;Password=xyz;";
            OracleConnection conn = new OracleConnection(oradb);
            OracleCommand cmd = conn.CreateCommand();
            cmd.CommandText = "tstpack.spAddCountry";  
            cmd.CommandType = CommandType.StoredProcedure;
            ...
            OracleParameter paramInsertedBy = new OracleParameter();
            paramInsertedBy.ParameterName = "pInsertedBy";
            paramInsertedBy.Value = aCountry.InsertedBy;  //aCountry.InsertedBy is a string
            cmd.Parameters.Add(paramInsertedBy);

//            CultureInfo ci = new CultureInfo("en-US");  //flail...
            OracleParameter paramInsertedOn = new OracleParameter();
            paramInsertedOn.ParameterName = "pInsertedOn";
//            paramInsertedOn.Value = DateTime.Now;  //just testing to see if it's WebForm issue
//            paramInsertedOn.Value = Convert.ToDateTime(DateTime.Now.ToString(), ci);  //flail!
            paramInsertedOn.Value = aCountry.InsertedOn;  //aCountry.InsertedOn is a DateTime
            cmd.Parameters.Add(paramInsertedOn);      
            ...
            conn.Open();
            cmd.ExecuteNonQuery();  //CRASH!  ORA-01840    
            conn.Close();    
            }

为了验证程序的流程是否正常,我尝试删除日期parm" pInsertedOn"从pl / sql和上面的parm列表中,一切正常。我知道我要和约会一起走出铁轨。有人能告诉我如何从MVC WebForm向Oracle传递日期吗?是否需要某种类型的演员?我也非常感谢一个例子。

非常感谢!

ps,我确实尝试在Pl / Sql中将parm类型更改为Varchar2并在Pl / Sql中自己进行一些转换,自动MVC绑定器阻碍了我的方式,强制的属性paramInsertedOn.OracleType DateTime 。我尝试将它强制为Varchar2,但也没有运气......

0 个答案:

没有答案