I've written the following method which counts the number of times a specific attribute value appears in the database. It works fine in Oracle SQL Developer but returns a: 'ORA-01722:invalid number' error when running in ASP.NET, so it must be an ASP.NET / C# problem.
The NTID attribute is a VarChar2, but only 3 values are actually non-numeric. Would it make any difference if I changed the data type to NUMBER? Currently, I can't change the data type as there are already values in the table.
Expand|Select|Wrap|Line Numbers
- public int CheckRegistration(string userId)
- {
- using (OracleConnection oce = new OracleConnection(ConnectionString))
- {
- string user = string.Format("'{0}'", userId);
- oce.Open();
- OracleCommand command = oce.CreateCommand();
- command.CommandType = CommandType.Text;
- string querystring = string.Format(@"
- SELECT COUNT(*) FROM TBLADMINCODES
- WHERE NTID = {0}", user);
- command.Prepare();
- }
- return (int) command.ExecuteScalar();
- }
What can I do to eliminate this error?
Thanks Matt.