C# 查询时将sqlite中的文本转换为int

C# 查询时将sqlite中的文本转换为int,c#,sqlite,C#,Sqlite,我想在选择以下两列后立即将它们转换为整数(它们作为文本放置在SQlite db中) string sql4 = "select seq, maxLen from abc where maxLen > 30"; 我想可以这样做…(使用cast) 不确定它是否正确,因为我似乎遇到了语法错误 如何将文本转换为double您需要在where子句中转换,而不是在您选择它的位置 string sql4 = "select seq, maxLen from abc where CAST(maxLen

我想在选择以下两列后立即将它们转换为整数(它们作为文本放置在SQlite db中)

 string sql4 = "select seq, maxLen from abc where maxLen > 30";
我想可以这样做…(使用cast)

不确定它是否正确,因为我似乎遇到了语法错误


如何将文本转换为double

您需要在
where
子句中转换,而不是在您选择它的位置

string sql4 = "select seq, maxLen from abc where CAST(maxLen as INTEGER) > 30";
此外,在当前的
cast
版本中,由于
cast
适用于单个字段,因此它将不起作用

关于你的问题:

如何将文本转换为双精度

把它变成现实,就像:

CAST(maxLen as REAL)

语法问题是在一个cast子句中放置了两个cast。试试这个:

string sql4 = "select cast(seq as int), cast(maxLen as int) 
               from abc where maxLen > 30"
正如Habib指出的,您应该类型转换where子句,否则比较不是数字而是文本

string sql4 = "select cast(seq as int), cast(maxLen as int) 
               from abc where cast(maxLen as int) > 30"
而且,转换为float很简单,可以使用float而不是int(或者可以使用REAL,它与SQLite中的数据类型相同)

string sql4 = "select cast(seq as int), cast(maxLen as int) 
               from abc where cast(maxLen as int) > 30"
cast(maxLen as float)