How to know if a field is numeric in Linq To SQL

前端 未结 7 1057
日久生厌
日久生厌 2020-12-15 11:18

I need to select the rows of a table where a column value is numeric, any Help?

EDIT: I have a varchar column and I need to select the ones that are numbers and the

相关标签:
7条回答
  • 2020-12-15 11:52

    SqlFunctions.IsNumeric

    http://msdn.microsoft.com/en-us/library/system.data.objects.sqlclient.sqlfunctions.isnumeric.aspx

    For example:

        private int GetLastGoodNumber(string PartNum)
        {
            return (from row in Db.SerialNo
                    where
                       row.PartNum == PartNum
                    let nullable = System.Data.Objects.SqlClient.SqlFunctions.IsNumeric(row.SerialNumber)
                    where nullable != null
                    select nullable.Value).Max();
        }
    
    0 讨论(0)
提交回复
热议问题