Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows CE上的异常“SqlException”(System.Data.SQLClient)_C#_Sql Server_Windows Ce - Fatal编程技术网

C# Windows CE上的异常“SqlException”(System.Data.SQLClient)

C# Windows CE上的异常“SqlException”(System.Data.SQLClient),c#,sql-server,windows-ce,C#,Sql Server,Windows Ce,执行命令时,会给出以下SqlException。已建立连接。客户端操作系统是查询SQL Server 2012数据库的模拟Windows CE 此行上会引发异常: SqlDataReader reader = Shared.command.GetCommand().ExecuteReader(); Shared是一类具有初始化静态对象的变量 密码 问题已经解决了。我的SQL参数是问题的原因 以下内容必须更改 List <SqlParameter> parameters = new

执行命令时,会给出以下SqlException。已建立连接。客户端操作系统是查询SQL Server 2012数据库的模拟Windows CE

此行上会引发异常:

SqlDataReader reader = Shared.command.GetCommand().ExecuteReader();
Shared是一类具有初始化静态对象的变量

密码
问题已经解决了。我的SQL参数是问题的原因

以下内容必须更改

List <SqlParameter> parameters = new List<SqlParameter>();
parameters.Add(new SqlParameter("BARCODE", tbxBarcode.Text));

Shared.command.SetCommand("SELECT * FROM table WHERE BARCODE_STRING = @BARCODE", parameters);

IV_Barcode barcode = new IV_Barcode();
DataTable table = barcode.Execute();
。。。为此:

List <SqlParameter> parameters = new List<SqlParameter>();
parameters.Add(new SqlParameter("@BARCODE", tbxBarcode.Text));

Shared.command.SetCommand("SELECT * FROM table WHERE BARCODE_STRING = @BARCODE", parameters);

IV_Barcode barcode = new IV_Barcode();
DataTable table = barcode.Execute();

使用调试器作为启动程序。。还可以使用{}将Sql对象包装在一个数组中。是的,问题在于参数,应该使用@BARCODE而不是BARCODE。
List <SqlParameter> parameters = new List<SqlParameter>();
parameters.Add(new SqlParameter("BARCODE", tbxBarcode.Text));

Shared.command.SetCommand("SELECT * FROM table WHERE BARCODE_STRING = @BARCODE", parameters);

IV_Barcode barcode = new IV_Barcode();
DataTable table = barcode.Execute();
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, TdsParserState state)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, TdsParserState state)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
   at System.Data.SqlClient.TdsParser.Run(RunBehavior run, SqlCommand cmdHandler, SqlDataReader dataStream)
   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
   at System.Data.SqlClient.SqlCommand.ExecuteReader()
   at Inventory_Checker.IV_Barcode.Execute()
   at Inventory_Checker.frmMain.tbxBarcode_LostFocus(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnLostFocus(EventArgs e)
   at System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 lParam)
   at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
   at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
   at System.Windows.Forms.Application.Run(Form fm)
   at Inventory_Checker.Program.Main()
List <SqlParameter> parameters = new List<SqlParameter>();
parameters.Add(new SqlParameter("BARCODE", tbxBarcode.Text));

Shared.command.SetCommand("SELECT * FROM table WHERE BARCODE_STRING = @BARCODE", parameters);

IV_Barcode barcode = new IV_Barcode();
DataTable table = barcode.Execute();
List <SqlParameter> parameters = new List<SqlParameter>();
parameters.Add(new SqlParameter("@BARCODE", tbxBarcode.Text));

Shared.command.SetCommand("SELECT * FROM table WHERE BARCODE_STRING = @BARCODE", parameters);

IV_Barcode barcode = new IV_Barcode();
DataTable table = barcode.Execute();