简体   繁体   English

C#中的条件异常中的数据类型不匹配

[英]data type mismatch in criteria exception in C#

i am making an application in which i insert a customer_Id with Double datatype in a Textbox1. 我正在制作一个在Textbox1中插入具有Double数据类型的customer_Id的应用程序。

i use the customer_ID's value to access the database of respective customer_ID. 我使用customer_ID的值来访问各个customer_ID的数据库。 i had converted the value of Textbox1 into Double datatype using 我已经使用将Textbox1的值转换为Double数据类型

double cust_ID;  
Cust_ID=Convert.ToDouble(Textbox1.Text);  

and the query is 和查询是

string s="select * from Customer where Customer_ID='"+Cust_ID+"'";

But yet i am getting the data type mismatch in criteria exception error. 但是,我在准则异常错误中得到的数据类型不匹配。

Don't put the value in single quites. 不要把价值放在单宁。 The following should work: 以下应该工作:

string s="select * from Customer where Customer_ID="+Cust_ID;

However, everyone else is also right - You shouldn't be using a double for an ID. 但是,其他所有人也都正确-ID不应使用双精度。 IDs should always be an int or a long depending on how many items you expect. ID应始终为intlong int ,具体取决于您期望的项目数。

ID使用整数而不是双精度数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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