Reputation: 4848
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);
//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();
}
Upvotes: 3
Views: 3316
Reputation: 70369
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.
Upvotes: 3
Reputation: 425033
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
Upvotes: 1
Reputation: 415820
Try removing the parentheses that you have: you don't need them.
Upvotes: 3