mercredi 28 octobre 2020

How to pass params to the method if a user leaves few params empty and wants to omit?

I have one web service to which i need to send multiple params but it's upto user that he can leave few empty and few filled but the problem is that if we pass empty or null the web service returns nothing and the vendor is not modifying it.

so we need to do something on our end.

I have done this that i took one string varaible and then append this to the url.

   If String.IsNullOrEmpty(txtEqptType.Text) Then
                Dim command As String = "Equips?$filter= TypeID eq 'Safety'"
            ElseIf String.IsNullOrEmpty(txtEquipID.Text) Then
                Dim command As String = "Equips?$filter= EquipID eq 'FIRE EXT 150'"
            ElseIf String.IsNullOrEmpty(txtPlant.Text) Then
                Dim command As String = "Equips?$filter= Plant eq 'MfgSys'"
            ElseIf String.IsNullOrEmpty(txtDescription.Text) Then
                Dim command As String = "Equips?$filter= Description eq 'Fire Extinguisher 150_1'"
            End If

but what I need to achieve is that if one param is empty i.e. not filled, then it shouldn't be passed to the webservice in the query string. Is there any short and solid way? bcz If I do, i will have to write a lot of if else condtions.

Aucun commentaire:

Enregistrer un commentaire