简体   繁体   中英

System.Data.SqlClient.SqlException: Incorrect syntax near ';'

I cannot figure out why I'm getting this error:

System.Data.SqlClient.SqlException: Incorrect syntax near ';'

on the ExecuteReader command. This is the command.CommandText statement:

comm.CommandText = "SELECT AcctNumb,TranCode,Code FROM dbo.tablbfee WHERE Code = @cd";

@cd is defined as:

 var feeb1 = prmt.Controls.Find("Bt3", true)[0];                        
 comm.Parameters.AddWithValue("@cd", feeb1.Text);

I use this exact same code when I find Bt2 and it works fine.

Any ideas?

I think code is integer column and you are trying to pass character string to it. Character string contains ; and it is not implicitly convertible to integer.

comm.Parameters.AddWithValue("@cd", feeb1.Text);

Always try to pass the right datatype, instead of calling AddwithValue

comm.Parameters.Add("@cd", SqlDbType.Int);
command.Parameters["@ID"].Value = feeb1.Text; // you will get error here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM