将DateTime从VB.NET解析到Oracle存储过程 [英] Parsing DateTime From VB.NET to Oracle Stored Procedure

查看:93
本文介绍了将DateTime从VB.NET解析到Oracle存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力使用Oracle的日期时间功能.

I've been struggling with Oracle's Date Time Function.

我的存储过程可以正常运行并且做得很好,但是我不知道如何解析VB.net的日期,以便存储过程可以从VB.net接收值?

I have stored procedure which runs properly and well done but I don't have any idea how can I parsing the date from VB.net so that the stored procedure can receive the value from VB.net?

没有人知道如何从VB.net解析值,在这种情况下,我谈论的是日期时间",因此它将是一个小时,一秒钟和一分钟.

Does anyone know how to parsing the value from VB.net, in this case I talk about the Date Time so it will be a hour, second and minute.

非常感谢您

这是.NET代码

Try
            Dim conn As New OracleConnection(connectionString(data(0), data(1), data(2)))
            conn.Open()
            Dim cmd As New OracleCommand
            cmd.Connection = conn
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "transactionme"
            Dim p1 As OracleParameter
            Dim p2 As OracleParameter
            Dim p3 As OracleParameter
            Dim p4 As OracleParameter
            Dim p5 As OracleParameter
            Dim p6 As OracleParameter
            Dim p7 As OracleParameter
            Dim p8 As OracleParameter
            Dim p9 As OracleParameter
            Dim p10 As OracleParameter
            p1 = cmd.Parameters.Add("param1", OracleDbType.NChar)
            p1.Value = ""
            p2 = cmd.Parameters.Add("param2", OracleDbType.NChar)
            p2.Value = "STD2"
            p3 = cmd.Parameters.Add("param3", OracleDbType.NChar)
            p3.Value = "RK001"
            p4 = cmd.Parameters.Add("param4", OracleDbType.NChar)
            p4.Value = "EK001"
            p5 = cmd.Parameters.Add("param5", OracleDbType.Date)
            p5.Value = "here is the problem"
            p6 = cmd.Parameters.Add("param6", OracleDbType.Date)
            p6.Value = "here is the problem"
            p7 = cmd.Parameters.Add("param7", OracleDbType.Date)
            p7.Value = "here is the problem"
            p8 = cmd.Parameters.Add("param8", OracleDbType.NChar)
            p8.Value = "Master Card"
            p9 = cmd.Parameters.Add("param9", OracleDbType.Int32)
            p9.Value = 30000

            Dim n As Integer
            n = cmd.ExecuteNonQuery()
            MessageBox.Show(n.ToString)
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try

参数应该是这样的,已经尝试了许多类似concat和其他的事情

The parameter should be like this, have tried many things like concat and others

to_date('2012-01-23 22:00', 'YYYY-MM-DD hh24:mi')

推荐答案

根据此

According to this MSDN Forum Posting the Oracle Date data type corresponds to the .Net Date data type.

从上方链接:

参数值应该是日期数据值,而不是字符串.由于基础表示形式是数字,因此无需在将日期作为参数传递时格式化日期.

The parameter value should be a Date data value and not a string. There is no need to format the date when you're passing it in as a parameter since the underlying representation is numeric.

p5 = cmd.Parameters.Add("param5", OracleDbType.Date)  
p5.Value = Convert.ToDateTime("Your Date here")  

编辑,尝试使用此方法分析您的日期/时间信息并转换您的字符串.

Edit try this to Parse your Date/time information and Convert your string.

  Private Function GetDateTime(dateFormat As String) As Date
    Dim split() As String = New String() {","}

    Return Convert.ToDateTime(dateFormat.Split(split, 2, StringSplitOptions.None)(0))

End Function

用法:

p5.Value = GetDateTime("2012-01-23 22:00, YYYY-MM-DD hh24:mi") 'or what ever your string variable is.

这篇关于将DateTime从VB.NET解析到Oracle存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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