Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do i initialize my arraylist
    text
    copied!<p>I have a function that adds items to my arraylist. my problem is that it only holds one item at a time since it is reinitializing the array lit every time I click my button. what is the syntax in VB to only initialize the array if it has not been created yet?</p> <pre><code> Dim itemSelectAs New ArrayList() Dim Quantities As New ArrayList() Dim itemQtyOrdered As Integer Public Sub ShtickDataList_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ShtickDataList.ItemCommand If e.CommandName = "addToCart" Then Dim itemQuantity As DropDownList = e.Item.FindControl("QuantityDropDown") itemQtyOrdered = itemQuantity.SelectedValue ItemSelect.Add(e.CommandArgument) Quantities.Add(itemQtyOrdered) Session("itemInCart") = ItemSelect Session("quantities") = Quantities viewInvoice() End If End Sub Protected Sub viewInvoice() Dim itemSelected As ArrayList = DirectCast(Session("itemInCart"), ArrayList) Dim QuantityofItem As ArrayList = DirectCast(Session("quantities"), ArrayList) Dim conn As SqlConnection Dim comm As SqlCommand Dim reader As SqlDataReader Dim purimConnection2 As String = ConfigurationManager.ConnectionStrings("Purim").ConnectionString conn = New SqlConnection(purimConnection2) comm = New SqlCommand("SELECT ProductName FROM Products WHERE ProductID = @ProductID", conn) Dim i As Integer For i = 0 To ItemSelect.Count - 1 comm.Parameters.Add("@ProductID", Data.SqlDbType.Int) comm.Parameters("@ProductID").Value = (ItemSelected.Count - 1) 'Next Try conn.Open() reader = comm.ExecuteReader() ViewCartlink.Text = "View Cart: (" &amp; ItemSelected.Count &amp; ")" Finally conn.Close() End Try End Sub </code></pre>
 

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