Results 1 to 6 of 6

Thread: CREATEPARAMETER class??

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    CREATEPARAMETER class??

    I have a SQL statements stored in the config.xml file.

    There is a WHERE clause in the sql statements. The values in the Where clause will be known only at runtime. How can I do this? Some one suggested me to use OLEDBParameter object.
    The sql statement is read from config.xml file


    //The value of sTerm will changed based on the resultset of previous query.

    string sTerm = "Overnight";

    ssql = "SELECT Term, BenchMark FROM RATESLIVE WHERE Pricing_Tier = 1 AND Term = '" + sTerm + "'";

    OleDbConnection oMSAccessConnection = new OleDbConnection(sConnectionstring);

    OleDbCommand oMSAccessCommand = new OleDbCommand(ssql, oMSAccessConnection);

    oMSAccessConnection.Open();

    OleDbDataReader oDataReader = oMSAccessCommand.ExecuteReader();

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: CREATEPARAMETER class??

    Your SQL code should be:
    Code:
    SELECT Term, BenchMark FROM RATESLIVE WHERE Pricing_Tier = 1 AND Term = @Term
    then at run time you simply add a corresponding parameter to your OleDbCommand:
    Code:
    oMSAccessCommand.Parameters.AddWithValue("@Term", "Overnight"); // or whatever value you want.
    This code is for .NET 2.0. In .NET 1.x you will have to use Add instead of AdWithValue. I really think that after 310 posts you should know to specify your version by now. Just because you don't think it's important for a particular question doesn't mean that it isn't. If you can't remember to check a radio button when you create a thread then put your version in your sugnature.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Re: CREATEPARAMETER class??

    My apolozies Jm. I always check the radio button to indicate the version. But some how I forgot when my 2 year old was distracting me sitting on my lap.

    Thanks for your response.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Re: CREATEPARAMETER class??

    jm,

    I get "Illegal variable or number" error.

    string ssql = "SELECT Term, Adv_Rate,FROM RATESLIVE WHERE Term = @Term ";


    OracleConnection _oOracleConnection = new OracleConnection(_sConnectionString);
    OracleCommand _oOracleCommand = new OracleCommand(ssql, _oOracleConnection);
    _oOracleCommand.Parameters.AddWithValue("@Term", "Overnight");

    _oOracleConnection.Open();
    //when executing next statement, the exception is thrown..
    return _oDataReader = _oOracleCommand.ExecuteReader();

    }

    System.Data.OracleClient.OracleException: ORA-01036: illegal variable name/numbe
    r

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: CREATEPARAMETER class??

    Sounds like an Oracle thing. Using "@ParameterName" is the convention for SQL Server via SqlClient. Maybe OracleClient requires a different method of naming parameters.

    I checked out the help topic for the OracleParameter class and the code example they provide prefixes parameter names with a lower case "p", so try "pTerm" as the parameter name instead of "@Term".
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Re: CREATEPARAMETER class??

    Its actually : instead of @

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width