By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,985 Members | 2,907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,985 IT Pros & Developers. It's quick & easy.

SQL Error in C# code

100+
P: 132
Hi there.

I have the following code in the body of a web method:

Expand|Select|Wrap|Line Numbers
  1. string maxCmd = "select max(aValue) + 1 from a_table where aValue < 1000";
  2. string newValue = string.Empty;
  3.  
  4. OracleCommand comm = new OracleCommand("maxCmd", conn);
  5. OracleDataReader reader = comm.ExecuteReader();
  6. while (reader.Read())
  7. {
  8.    newValue = reader[0].ToString();
  9. }
  10.  
  11.  
This produces an error message of the form "Invalid SQL command" though I can't see what I am missing here as this runs okay in the sql client. Can anybody see my mistake please?

Thank you.

M :o)
Feb 10 '09 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 750
PRR
well you haven't opened connection?
Feb 10 '09 #2

100+
P: 132
@DeepBlue
Yes I have but I haven't shown that part of the code sample.

Thank you.

M :o)
Feb 10 '09 #3

100+
P: 132
Hi there.

I just solved it. I had the string for the sql command in quotes in the command definition:

OracleCommand comm = new OracleCommand("maxCmd", conn);

This should be:

OracleCommand comm = new OracleCommand(maxCmd, conn);

Thank you.

M :o)
Feb 10 '09 #4

Expert 100+
P: 750
PRR
oh yeah! i missed that ... do continue to post your queries on Bytes
Feb 10 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.