How to join these 2 lines

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bluenose
    New Member
    • Apr 2012
    • 56

    How to join these 2 lines

    Hello

    How would I join these 2 lines of code, please?

    Code:
    cmd.Parameters.AddWithValue("@uniqueCode", Convert.ToString(Request.QueryString("uniqueCode")))
    
    cmd.Parameters.AddWithValue("@strEmail", Convert.ToString(Request.QueryString("strEmail")))
    Thank you.
  • jns42
    New Member
    • Apr 2018
    • 3

    #2
    When you say "combine", what is your end-goal? Are you trying to issue a single statement cover both?

    If you have a collection of keys (e.g. "uniqueCode ", "strEmail", etc) to be read, then you could loop through that collection, issuing the call above once for each key. (In case you aren't aware, the List is in System.Collecti ons.Generic.)

    So, if you had something like this defined:
    Code:
    Dim keys As List(Of String)
    And then had it populated with all of the keys you're wanting to parse (i.e. keys.Add("uniqu eCode") ), you could issue one statement inside of a loop, such as:
    Code:
    Dim key As String
    For Each key In keys
        cmd.Parameters.AddWithValue("@" & key, Convert.ToString(Request.QueryString(key)))
    Next key
    `

    I hope this helps.

    -J

    EDIT: It may also be of interest to note that (in VB.Net, anyway) the List(...) types have a "ForEach" method on them that makes the same loop, so the above code could also be written as:
    Code:
    keys.ForEach(cmd.Parameters.AddWithValue("@" & key, Convert.ToString(Request.QueryString(key))))
    Last edited by jns42; Apr 18 '18, 01:11 PM. Reason: Additional information

    Comment

    Working...