Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.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# 将Id设置为文本框中包含的数字_C#_Wpf - Fatal编程技术网

C# 将Id设置为文本框中包含的数字

C# 将Id设置为文本框中包含的数字,c#,wpf,C#,Wpf,嗨,我想用一个表中的名称填充一个组合框,其中id是textbox中包含的数字。txtPartId是从另一个页面填充的,就像txtPart中的名称一样。运行此命令时出现的错误是“无效列名”txtPartId 快速而肮脏的答案是进行以下更改: string Query = "select * from Re where Part_PartID = " + txtPartId.Text; 假设Part_PartID是一个整数 如果是字符串,则可以使用: string Query = string.F

嗨,我想用一个表中的名称填充一个组合框,其中id是textbox中包含的数字。txtPartId是从另一个页面填充的,就像txtPart中的名称一样。运行此命令时出现的错误是“无效列名”txtPartId


快速而肮脏的答案是进行以下更改:

string Query = "select * from Re where Part_PartID = " + txtPartId.Text;
假设Part_PartID是一个整数

如果是字符串,则可以使用:

string Query = string.Format("select * from Re where Part_PartID = '{0}'", txtPartId.Text);
编译器不会将
txtPartId
中的文本值为您注入查询字符串


但是,这引入了SQL注入的范围,因此我强烈建议您对查询进行参数化。这方面的示例很多。

这听起来像是查询/表中的一个问题
string Query = string.Format("select * from Re where Part_PartID = '{0}'", txtPartId.Text);