Solved

ArrayList

Posted on 2007-04-03
6
726 Views
Last Modified: 2013-11-26
Hi,

I'm using ASP.NET 2005 with SQL Server.  I need to create an array to store 2 values which are StartDate and EndDate.  The dates will be used as stored procedure parameters to pass to SQL Server. I need to store the StartDate and EndDate into the array.  I created an ArrayList, but was not sure how to go about getting the EndDate value. Do I concatenate the StartDate and EndDate and then retrieve the values?  Could someone show me an example of creating the ArrayList and then retrieving both values using an iteration because I could have more than one StartDate and EndDate values? My code so far is as follows:

‘Assumption:  The ArrayList gets its data by an ADO.NET DataTable.

Dim DateRange As String
DateRange = rdrStartDate + " " + rdrEndDate
                        arrList.Add(DateRange)

Thanks,
Denise
0
Comment
Question by:DeniseGoodheart
  • 3
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
Elvio Lujan earned 460 total points
ID: 18846556
you can create a structure that way:

        Private Structure dates
            Dim StartDate As DateTime
            Dim EndDate As DateTime
        End Structure

Dim DateRange As dates
DateRange.StartDate = rdrStartDate
DateRange.EndDate = rdrEndDate
arrList.Add(DateRange)
0
 
LVL 22

Assisted Solution

by:_TAD_
_TAD_ earned 40 total points
ID: 18846628

An arraylist stores an object. That Object could be anything - including another array or paired object.


                  ArrayList lst = new ArrayList();

                  lst.Add(new string[]{"Start1","End1"});
                  lst.Add(new string[]{"Start2","End2"});
                  lst.Add(new string[]{"Start3","End3"});

                  string[] str;
                  for (int i=0;i<lst.Count;i++)
                  {
                        str = (string[])lst[i];
                        Console.WriteLine("Start Date is: {0}", str[0]);
                        Console.WriteLine("End Date is: {0}", str[1]);
                  }
0
 

Author Comment

by:DeniseGoodheart
ID: 18846791
Hi lem2802:

Thanks for your code.  How do I create the iteration loop to retrieve the values?  I tried the following with no success.

Private Sub TestArrayList()
        Dim pStartDate As dates
        Dim pEndDate As dates
        Dim i As Integer
        For i = 0 To arrList.Count - 1
            pStartDate = arrList.Item(0)
            pEndDate = arrList.Item(1)
        Next
    End Sub

Thanks,
Denise
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:DeniseGoodheart
ID: 18846811
Hi TAD:

Thanks for your code.  How to I get the values?  I tried the following with no success:

Private Sub TestArrayList2()

        Dim paramStartDate As String
        Dim paramEndDate As String

        Dim i As Integer = 0
        Do While (i < lst.Count)
            paramStartDate = lst(0)
            paramEndDate = lst(1)
            i = (i + 1)
        Loop
Thanks,
Denise
0
 
LVL 18

Assisted Solution

by:Elvio Lujan
Elvio Lujan earned 460 total points
ID: 18846904
Private Sub TestArrayList()
        Dim p As dates
        Dim i As Integer
        For i = 0 To arrList.Count - 1
            p.StartDate = ctype(arrList.Item(i), dates).StartDate
            p.EndDate = ctype(arrList.Item(i), dates).EndDate
         Next
    End Sub
0
 

Author Comment

by:DeniseGoodheart
ID: 18847005
Many thanks,
Denise
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question