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

前端 未结 7 1103
日久生厌
日久生厌 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:30

    (Edited to suit your needs)

    So, given the fact that you cannot use Integer.TryParse, the following is not feasible:

    int i;
    var rowsWithInts = (From r In dc.YourRows Where Integer.TryParse(r.Column, i));
    var rowsWithoutInts = (From r In dc.YourRows Where !Integer.TryParse(r.Column, i));
    

    Is it possible that you create a stored procedure and link it to the DataContext via the Methods Pane? In that case you can do in your SQL the following:

    -- Rows with integers
    SELECT * FROM your_table WHERE ISNUMERIC(varchar_column) = 1
    -- Rows without integers
    SELECT * FROM your_table WHERE ISNUMERIC(varchar_column) = 0
    

    Does this helps?

提交回复
热议问题