大佬教程收集整理的这篇文章主要介绍了c# – 错误在我的SQL语句中说“缺少右括号”……但事实并非如此!救命?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
(由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'";
这是错误消息:
我的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(); }
以上是大佬教程为你收集整理的c# – 错误在我的SQL语句中说“缺少右括号”……但事实并非如此!救命?全部内容,希望文章能够帮你解决c# – 错误在我的SQL语句中说“缺少右括号”……但事实并非如此!救命?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。