I have to translate some code from VB6 into C#. rs
is a Recordset object:
If rs.Fields("mycolumn") < 5 Then
myarray(Val(rs.Fields("mycolumn"))) = myarray(Val(rs.Fields("mycolumn"))) + 1".
End If
The problem here is comparing the column and number, because the column is a string. I already tried the VisualBasic Val()-method, but it doesn't behave totally the same?
I used this, but it doesn't give the same expression as the VB6 one. Some of the records pass thru, when they shouldn't.
if (Microsoft.VisualBasic.Conversion.Val(rs.Rows[k]["mycolumn"]) < 5)
{
}
您应该使用int.Parse或int.TryParse将字符串转换为数字,然后可以进行比较:
if(int.Parse(rs.Rows[k]["mycolumn"]) < 5) { ... }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.