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
This function is giving an ORA-00911 invalid character error. I have other methods of the same style and these are functioning correctly. Any advise on where I am going wrong here please? Thanks
I think the issue is with the wrong quotes in the SQL statement for the year i.e. : ’YYYY’
Change it to 'YYYY'
Replace the line:
command.CommandText = "select VAL1, VAL2, Year from local.proc where id = :idnumber and Year = to_number(to_char(sysdate,’YYYY’))"
with
command.CommandText = "select VAL1, VAL2, Year from local.proc where id = :idnumber and Year = to_number(to_char(sysdate,'YYYY'))"