SQL Error in C# code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • E11esar
    New Member
    • Nov 2008
    • 132

    SQL Error in C# code

    Hi there.

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

    Code:
    string maxCmd = "select max(aValue) + 1 from a_table where aValue < 1000";
    string newValue = string.Empty;
    
    OracleCommand comm = new OracleCommand("maxCmd", conn);
    OracleDataReader reader = comm.ExecuteReader();
    while (reader.Read())
    {
       newValue = reader[0].ToString();
    }
    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)
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    well you haven't opened connection?

    Comment

    • E11esar
      New Member
      • Nov 2008
      • 132

      #3
      Originally posted by DeepBlue
      well you haven't opened connection?
      Yes I have but I haven't shown that part of the code sample.

      Thank you.

      M :o)

      Comment

      • E11esar
        New Member
        • Nov 2008
        • 132

        #4
        Solved

        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(m axCmd, conn);

        Thank you.

        M :o)

        Comment

        • PRR
          Recognized Expert Contributor
          • Dec 2007
          • 750

          #5
          oh yeah! i missed that ... do continue to post your queries on Bytes

          Comment

          Working...