2011-09-12 36 views
0
Public Shared Function GetData(ByVal id As Integer) As List(Of SomeClass) 
      Dim command As New OracleCommand  
      Dim conn As New OracleConnection(WebConfigurationManager.ConnectionStrings("ConnectionString").ToString) 
      Dim param As New OracleParameter 
      param.ParameterName = "idnumber" 
      param.Value = id 
      param.DbType = DbType.Int32 
      command.Parameters.Add(param) 

      command.Connection = conn 
      command.CommandText = "select VAL1, VAL2, Year from local.proc where id = :idnumber and Year = to_number(to_char(sysdate,’YYYY’))" 

      Dim reader As OracleDataReader 
      Dim someList As New List(Of SomeClass) 

      connection.Open() 
      reader = command.ExecuteReader() 
      While reader.Read 
       Dim someClass As New SomeClass 
       someClass.VAL1 = reader("VAL1") 
       someClass.VAL2 = reader("VAL2") 
       someClass.Year = reader("YEAR") 
       someList.Add(someClass) 
      End While 
      connection.Close() 
      Return someList 
     End Function 

此函数给出ORA-00911无效字符错误。我有其他相同风格的方法,并且这些方法运行正常。任何建议我要去哪里错了?由于VB.net函数给出ORA-00911无效字符错误

+0

你缺少一个参数':idnumber' - 你有在你的实际代码? –

回答

3

我认为这个问题是在SQL语句中的错误报价为当年即:’YYYY’

将其更改为'YYYY'

将行:

command.CommandText = "select VAL1, VAL2, Year from local.proc where id = :idnumber and Year = to_number(to_char(sysdate,’YYYY’))" 

command.CommandText = "select VAL1, VAL2, Year from local.proc where id = :idnumber and Year = to_number(to_char(sysdate,'YYYY'))" 
2

看起来你是使用格式化的撇号。它

to_char(sysdate,’YYYY’ 

尝试改变

to_char(sysdate,'YYYY' 
相关问题