string必须正好是一个字符长 [英] string must be exactly one character long
问题描述
我正面临一个问题,我不知道为什么会发生这种情况请帮助。
当我尝试获取linq查询的第一个结果时,查询返回null值,而在db中,那里是记录。
当我通过PosCustomerID = 00445856363109679106工作正确没有错误。但当我通过PosCustomerID = 00445856363109679107时,它抛出异常:字符串必须正好是一个字符长
我的代码查询是:
< pre lang =" C#"> POSCustomer updCustomer =(来自lC in UpdateCustomerDB.POSCustomers
其中lC.POSCustomerID == lBShipToAddress.PosCustomerID
select lC).Single();
i也试试这个:
1)POSCustomer updCustomer =(来自lC in UpdateCustomerDB.POSCustomers
其中lC.POSCustomerID == lBShipToAddress.PosCustomerID
select lC).SingleOrDefault();
2)
POSCustomer updCustomer =(来自lC in UpdateCustomerDB.POSCustomers
其中lC.POSCustomerID == lBShipToAddress.PosCustomerID
select lC).FirstOrDefault();
3)
POSCustomer updCustomer =(from lC in UpdateCustomerDB.POSCustomers
其中lC.POSCustomerID == lBShipToAddress.PosCustomerID
select lC).First();
my为该fiels生成的linq.dbml代码如下:
[global :: System.Data.Linq.Mapping.ColumnAttribute(Storage =& amp; quot; _POSCustomerID& amp; ; amp; quot;,DbType =& amp; quot; VarChar(23)NOT NULL& amp; quot;,CanBeNull = false,IsPrimaryKey = true)]
public string POSCustomerID
{
get
{
返回this._POSCustomerID;
}
set
{
if((this._POSCustomerID!= value))
{
this .OnPOSCustomerIDChanging(value);
this.SendPropertyChanging();
this._POSCustomerID = value;
this.SendPropertyChanged(& amp; POSCustomerID& amp; quot;);
this.OnPOSCustomerIDChanged();
}
}
}& lt; / pre& gt;< / pre>
=
i am facing one problem, i don't know why this occurs please help.
when i try to get first result of the linq query, query return null value, while in db, there is record.
when i pass PosCustomerID=00445856363109679106 is working corrent no error. but when i pass PosCustomerID=00445856363109679107 its throw an exception:"string must be exactly one character long"
my code query is:
<pre lang="C#"> POSCustomer updCustomer = (from lC in UpdateCustomerDB.POSCustomers
where lC.POSCustomerID == lBShipToAddress.PosCustomerID
select lC).Single();
i also try this:
1)POSCustomer updCustomer = (from lC in UpdateCustomerDB.POSCustomers
where lC.POSCustomerID == lBShipToAddress.PosCustomerID
select lC).SingleOrDefault();
2)
POSCustomer updCustomer = (from lC in UpdateCustomerDB.POSCustomers
where lC.POSCustomerID == lBShipToAddress.PosCustomerID
select lC).FirstOrDefault();
3)
POSCustomer updCustomer = (from lC in UpdateCustomerDB.POSCustomers
where lC.POSCustomerID == lBShipToAddress.PosCustomerID
select lC).First();
my linq.dbml code generated for that fiels are below:
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage=&quot;_POSCustomerID&quot;, DbType=&quot;VarChar(23) NOT NULL&quot;, CanBeNull=false, IsPrimaryKey=true)]
public string POSCustomerID
{
get
{
return this._POSCustomerID;
}
set
{
if ((this._POSCustomerID != value))
{
this.OnPOSCustomerIDChanging(value);
this.SendPropertyChanging();
this._POSCustomerID = value;
this.SendPropertyChanged(&quot;POSCustomerID&quot;);
this.OnPOSCustomerIDChanged();
}
}
}</pre></pre>
=
推荐答案
看这里: http://lmgtfy.com/?q=%22string+must +是+正好+一个+字符+长%22 [ ^ ]
或者在这里: http://stackoverflow.com/questions/1190328/linq-to-sql-exception-string-must-be-exactly-one-character -long [ ^ ]
Look here: http://lmgtfy.com/?q=%22string+must+be+exactly+one+character+long%22[^]
OR here: http://stackoverflow.com/questions/1190328/linq-to-sql-exception-string-must-be-exactly-one-character-long[^]
这篇关于string必须正好是一个字符长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!