2011-09-12 65 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'