本文介绍了将OracleParameter与C#TimeSpan一起使用-文字不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了广泛的搜索,但找不到任何示例.

I made an extensive search but I couldn't find any example about this.

我有一个TimeSpan类型的.NET变量,我需要将其放入Oracle DB的IntervalDayToSecond记录中.

I have a .NET variable of type TimeSpan and I need to put it into an IntervalDayToSecond record of an Oracle DB.

请参考 http://docs.oracle.com/html/B14164_01/featOraCommand. htm 在此页面上,应该可以将TimeSpan对象作为OracleParameter传递并以IntervalDayToSecond类型的记录将其插入到我的Oracle DB中.

Referring to http://docs.oracle.com/html/B14164_01/featOraCommand.htm this page, it should be possible to pass a TimeSpan object as an OracleParameter and get it inserted into my Oracle DB in a record of IntervalDayToSecond type.

这是代码:

OracleParameter t = new OracleParameter("PAR_T", _msg.t);

我尝试了各种方法,还明确指定了DBType(这不是必需的):

I tried it in every way, also explicitly specifying the DBType (it shouldn't be necessary):

OracleParameter t = new OracleParameter("PAR_T", _msg.t);
taxi.OracleDbType = OracleDbType.IntervalDS;

我总是从Oracle得到相同的错误:

I always get the same error from Oracle:

我不知道如何使它工作.我在此应用程序中使用了数十个参数(类型为StringIntegerDate),它们都可以正常工作.在Google上,我找不到使用c#TimeSpan作为参数的某人的单个示例.有没有人尝试过这个?

I can't understand how to make it work; I use dozens of parameters in this application (of type String, Integer, Date) and they all are working. On Google I can't find a single example of someone using c# TimeSpan as Parameter. Has anyone ever tried this?

推荐答案

好,那绝对是我的错.好老的OracleParameter做得很好.问题出在查询的其他地方.

Ok, it was definitely my fault.Good old OracleParameter was doing his job nicely; the problem was elsewhere in the query.

因此,我在此确认是否可以将TimeSpan变量绑定到Oracle Interval Day To Second记录.

So I hereby confirm that it is possible to bind a TimeSpan variable to an Oracle Interval Day To Second record.

string s = "00:20";
TimeSpan ts = TimeSpan.parse(s);
OracleParameter op = new OracleParameter("PAR_T", ts);

这将创建一个名为PAR_T的参数,该参数可在查询中用于将值插入Interval Day To Second记录中.

This creates a parameter named PAR_T which can be used in a query to insert a value into a Interval Day To Second record.

这篇关于将OracleParameter与C#TimeSpan一起使用-文字不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 01:59