Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I know a little PHP but I'm assuming that $position is a zero-based index. If it's not, then you would swap the two lines of code that declare the position variable. Comments begin with the ' character.</p> <pre><code>'Request.Params accesses parameters from form posts, query string, etc. Dim pairs = Request.Params("listItem").Split("&amp;") For i As Integer = 0 To pairs.Length - 1 Dim token = pairs(i) Dim position = i.ToString() 'string position = (i + 1).ToString(); Dim id = Convert.ToInt32(token.Split("=")(1)) Dim sql = "UPDATE table SET position = " + position + " WHERE [id] = " + id.ToString() 'This line does the same thing, a bit more eloquently and efficiently 'Dim sql = String.Format("UPDATE table SET position = {0} WHERE [id] = {1}", position, id.ToString()) Next </code></pre> <hr> <p>I did this in C# first because I did not notice that you said VB.net. So here's the C# version. Thought I might as well leave it in. I made this a little wordy to demonstrate some of the nuances of C# and for clarity.</p> <pre><code>// Request.Params accesses parameters from form posts, query string, etc. string[] pairs = Request.Params["listItem"].Split('&amp;'); for (int i = 0; i &lt; pairs.Length; i++) { string token = pairs[i]; string position = i.ToString(); // string position = (i + 1).ToString(); int id = Convert.ToInt32(token.Split('=')[1]); string sql = "UPDATE table SET position = " + position + " WHERE [id] = " + id; // This line does the same thing, a bit more eloquently and efficiently //string sql = String.Format("UPDATE table SET position = {0} WHERE [id] = {1}", position, id.ToString()); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload