422,929 Members | 1,355 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,929 IT Pros & Developers. It's quick & easy.

How to join these 2 lines

P: 46
Hello

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

Expand|Select|Wrap|Line Numbers
  1.  
  2. cmd.Parameters.AddWithValue("@uniqueCode", Convert.ToString(Request.QueryString("uniqueCode")))
  3.  
  4. cmd.Parameters.AddWithValue("@strEmail", Convert.ToString(Request.QueryString("strEmail")))
Thank you.
Apr 17 '18 #1
Share this Question
Share on Google+
1 Reply


jns42
P: 3
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.Collections.Generic.)

So, if you had something like this defined:
Expand|Select|Wrap|Line Numbers
  1. 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("uniqueCode") ), you could issue one statement inside of a loop, such as:
Expand|Select|Wrap|Line Numbers
  1. Dim key As String
  2. For Each key In keys
  3.     cmd.Parameters.AddWithValue("@" & key, Convert.ToString(Request.QueryString(key)))
  4. 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:
Expand|Select|Wrap|Line Numbers
  1. keys.ForEach(cmd.Parameters.AddWithValue("@" & key, Convert.ToString(Request.QueryString(key))))
Apr 18 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.