c# – 错误在我的SQL语句中说“缺少右括号”……但事实并非如此!救命?

c# – 错误在我的SQL语句中说“缺少右括号”……但事实并非如此!救命?,第1张

概述这是我在C#程序中的陈述: (由gbn编辑,格式清晰,所以不是全部在一行) DbCommand.CommandText = @"SELECT HIST.MBRSEP, HIST.LOCATION, HIST.BILLTYPE, HIST.BILLMOYR, LOCINFO.CYCLE, LOCINFO.DIST, LOCINFO.LOCATIO 这是我在C#程序中的陈述:

(由gbn编辑,格式清晰,所以不是全部在一行)

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'";

这是错误消息:

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

我的SQL语句中只有两个括号,一个是右边的,一个是左边的.我不确定错误告诉我的是什么.有什么建议?

编辑:以下是如何定义参数:

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

这是我将它们添加到DbCommand的地方:

DbCommand.Parameters.AdDWithValue("@CYCLE",cycle);        DbCommand.Parameters.AdDWithValue("@disTRICT",district);

这是我的完整代码,当有人点击我的表单上的“转到”按钮时触发:

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,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",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();    }
解决方法 问题可能是您使用oracle保留字作为列名和param名称 – 即CYCLE …
这样做可能会导致DB的奇怪和不稳定的行为!

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

根据您的数据库提供程序,您可能希望使用:而不是@表示params.

总结

以上是内存溢出为你收集整理的c# – 错误在我的SQL语句中说“缺少右括号”……但事实并非如此!救命?全部内容,希望文章能够帮你解决c# – 错误在我的SQL语句中说“缺少右括号”……但事实并非如此!救命?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1217082.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存