如何在DataTable int16字段上执行操作 [英] How to perform operations on DataTable int16 field
问题描述
大家好!
我很难对DataTable的值进行操作。
有些东西我不了解数据类型,我被卡住了。
长话短说,我已经制作并测试了这个查询到我的数据库。我知道它会返回我正在寻找的东西。
SELECT TOP( 1 )No_Membre FROM Infos_Membres WHERE No_Membre BETWEEN 1000 AND 5999 ORDER BY No_Membre DESC
现在,该查询的结果在DataTable中,.GetType()方法返回一个System.Int16
我希望能够使用结果,只需加1即可。
我试过:
int New_No = Results.Rows [ 0 ] [ < span class =code-string> No_Membre] + 1 ;
但它不起作用并返回
错误 4 运算符 ' + '不能应用于'object'和'int'类型的操作数
有人会好好告诉我我应该如何处理DataTables的数字。
谢谢!
如果您确定结果不为空,则.Rows不是null,并且[0]不是null并且是Int,那么你可以这样做:
int New_No =( int )Results.Rows [ 0 ] [ No_Membre] + 1 ;
Hi everyone !
I'm having a hard time performing an operation on a value from a DataTable.
There is something I don't understand about the data types and I'm stuck.
Long story made short, I've made and tested this query to my database. I know it returns what I'm looking for.
SELECT TOP(1) No_Membre FROM Infos_Membres WHERE No_Membre BETWEEN 1000 AND 5999 ORDER BY No_Membre DESC
Now, the results of that query is in a DataTable and the .GetType() method returns a System.Int16
I'd like to be able to use that result and just add 1 to it.
I tried to do :
int New_No = Results.Rows[0]["No_Membre"] + 1;
but it doesn't work and returns
Error 4 Operator '+' cannot be applied to operands of type 'object' and 'int'
Would someone be nice enough to tell me how I'm supposed to deal with "numbers" from DataTables.
Thank You !
If you are sure that Results is not null, .Rows is not null, and the [0] is not null and is an Int, then you can do something like this:
int New_No = (int)Results.Rows[0]["No_Membre"] + 1;
这篇关于如何在DataTable int16字段上执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!