0

I am trying to select data from DataTable using ISNUMERIC function, unfortunately I get error below:

System.Data.EvaluateException: "The expression contains the undefined function call ISNUMERIC()."

this is my current code (sorry some parts are in German but to translate I don't think it makes sense)

 Public dtFakturas As New DataTable



  Artikelgruppe_Einfuegen(rows:=dtFakturas.Select("FAK_KundenNr = " & Adr_Nr &
                                                                " AND Liegenschaft = '" & Liegenschaft & "' " &
                                                                " AND Mandant = '" & Mandant & "' " &
                                                                " AND von = '" & VerrechnungsPeriode.Von & "'" &
                                                                " AND bis = '" & VerrechnungsPeriode.Bis & "'" &
                                                                " AND FAK_BoMatNr <> ''", "FAK_BoMatNr").Where(Function(r) IsNumeric(r("FAK_BoMatNr"))),
                                        Postable:=PosTable,
                                        Adr_Nr:=Adr_Nr,
                                        Mandant:=Mandant,
                                        Ueberschrift:="", MasterMandantConnectionString:=MastermandantConnectionString,
                                        Verrechnen_bis:=VerrechnungsPeriode.Bis)


 Private Function IsNumeric(ByVal o As Object) As Boolean
        Dim result_ignored As Decimal
        Return o IsNot Nothing AndAlso Not (TypeOf o Is DBNull) AndAlso Decimal.TryParse(Convert.ToString(o), result_ignored)
    End Function

my question is: how do i correct a select query to function properly and only give me values that are ISNUMERIC?

Mara
  • 365
  • 1
  • 10
  • Most of the information in the question is not relevant, and what would be relevant is missing. If `Artikelgruppe_Einfuegen` calls [`DataTable.Select`](https://learn.microsoft.com/en-us/dotnet/api/system.data.datatable.select?view=netframework-4.8#System_Data_DataTable_Select_System_String_), which has nothing to do with SQL or querying a database, then your options are listed [here](https://learn.microsoft.com/en-us/dotnet/api/system.data.datacolumn.expression?view=netframework-4.8). – GSerg Jan 31 '20 at 09:14
  • @GSerg thanks for the reply, could you please give me an example that could correct my choice – Mara Jan 31 '20 at 09:16
  • Does this answer your question? [Check datatable column contains numeric values](https://stackoverflow.com/questions/8836002/check-datatable-column-contains-numeric-values) – GSerg Jan 31 '20 at 09:29
  • @GSerg ok I included this example you gave me, can you help me and tell me how to include in the "Dim filtered" other criteria that were applied in dtFakturas.Select. – Mara Jan 31 '20 at 10:18
  • IsNumeric is a reserved word of Visual Basic. Rename your function in IsThisNumeric or something else. – G3nt_M3caj Jan 31 '20 at 10:42
  • 1
    @G3nt_M3caj `IsNumeric` is not a reserved word in Visual Basic. It is a function in `Microsoft.VisualBasic.Information`. It is not a problem to define your own function with the same name. – GSerg Jan 31 '20 at 11:00
  • @Mara `dtFakturas.Select("FAK_KundenNr = ...").Where(Function(r) IsNumeric(r("FAK_BoMatNr")))`? – GSerg Jan 31 '20 at 11:03
  • @GSerg aha, I'll try so, thanks with the suggestion – Mara Jan 31 '20 at 11:05
  • @Gserg, Thanks for your reply. I knew what is IsNumeric otherwise I doesn’t write a comment under this question. But, always is better practice using custom names in methods and variables. Was this my context/advice. :) – G3nt_M3caj Jan 31 '20 at 11:12
  • @GSerg I corrected the code in question, now I'm getting this error, can you please look where I'm wrong ("System.InvalidCastException: "The object of type" WhereArrayIterator`1 [System.Data.DataRow] "cannot be converted to type" System.Data.DataRow [] "."") – Mara Jan 31 '20 at 11:23
  • @Mara Append `.ToArray()`. – GSerg Jan 31 '20 at 11:25
  • Just throwing it out there since I can't see the full code; what if you change `Private Function IsNumeric` to `Public Function IsNumeric`? – J. Scott Elblein Jan 31 '20 at 18:47

0 Answers0