开发者

Error says "Missing right parenthesis" in my SQL statement... but it's not! Help?

Here's my statement from my C# program:

(edit by gbn, formatted for clarity so not all on one line)

DbCommand.CommandText =
             @"SELECT 
      HIST.MBRSEP, HIST.LOCATION, HIST.BILLTYPE, HIST.BILLMOYR, LOCINFO.CYCLE, 
      LOCINFO.DIST, LOCINFO.LOCATION
    FROM 
      (CAV_MBRHISTDEL AS HIST INNER JOIN CAV_LOCINFODETL AS LOCINFO ON HIST.LOCATION = LOCINFO.LOCATION)
    WHERE
       LOCINFO.CYCLE = @CYCLE AND 
       LOCINFO.DIST = @DISTRICT AND 
       HIST.BILLTYPE = '09' AND 
       HIST.BILLMOYR <> '9999'";

Here's the error message:

ERROR [HY000] [Oracle][ODBC][Ora]ORA-00907: missing right parenthesis

There's only 2 parenthesis in my SQL statement, a right one and a left one. I'm not sure what the error is telling me. Any advice?

EDIT: Here is how the parameters are defined:

        string cycle = cbCycle.Text;
        string district = cbDistrict.Text.Substring(0,2);

And here is where I add them to the DbCommand:

        DbCommand.Parameters.AddWithValue("@CYCLE", cycle);
        DbCommand.Parameters.AddWithValue("@DISTRICT", district);

Here's my complete code that triggers when someone clicks the 'Go' button on my form:

private void btnGo_Click(object sender, EventArgs e)
    {
        //get parameters
        string cycle = cbCycle.Text;
        string district = cbDistrict.Text.Substring(0,2);

        //create a connection to the database
        OdbcConnection DbConnection = new OdbcConnection("DSN=UPN2;uid=xxx;pwd=xxxx");
        DbConnection.Open();

        //create a command to extract the required data and
        //assign it to the connection string
        OdbcCommand DbCommand = DbConnection.CreateCommand();
        DbCommand.CommandText =
             @"SELECT HIST.MBRSEP, HIST.LOCATION, HIST.BILLTYPE, HIST.BILLMOYR, LOCINFO.CYCLE, LOCINFO.DIST, LOCINFO.LOCATION FROM CAV_MBRHISTDEL AS HIST INNER JOIN CAV_LOCINFODETL AS LOCINFO ON HIST.LOCATION = LOCINFO.LOCATION WHERE LOCINFO.CYCLE = @CYCLE AND LOCINFO.DIST = @DISTRICT AND HIST.BILLTYPE = '09' AND HIST.BILLMOYR <> '9999'; ";

        DbCommand.Parameters.AddWithValue("@CYCLE", cycle);
        DbCommand.Parameters.AddWithValue("@DISTRICT", district);

        开发者_StackOverflow//Create a DataAdapter to run the command and fill the datatable
        OdbcDataAdapter da = new OdbcDataAdapter();
        da.SelectCommand = DbCommand;
        DataTable dt = new DataTable();
        da.Fill(dt);


        tbOutput.Text = PrintDataTable(dt);

        DbCommand.Dispose();
        DbConnection.Close();

    }


the problem might be that you are using an oracle reserved word as a column name and as a param name - namely CYCLE... doing so might result in strange and erratic behaviour of the DB!

see http://download.oracle.com/docs/cd/B19306_01/em.102/b40103/app_oracle_reserved_words.htm

Depending on your db provider you might want to use : instead of @ for params.


Try removing the parentheses that you have: you don't need them.


You're missing the SELECT from the inner query. Try this:

...
FROM 
    (SELECT CAV_MBRHISTDEL AS HIST -- Added SELECT
    INNER JOIN CAV_LOCINFODETL AS LOCINFO ON HIST.LOCATION = LOCINFO.LOCATION)
WHERE
...

You have:

FROM 
    (CAV_MBRHISTDEL ... -- Missing SELECT
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜